本文整理汇总了PHP中Model_User::create_email方法的典型用法代码示例。如果您正苦于以下问题:PHP Model_User::create_email方法的具体用法?PHP Model_User::create_email怎么用?PHP Model_User::create_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model_User
的用法示例。
在下文中一共展示了Model_User::create_email方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_create
public function action_create()
{
try {
if (!Valid::email(core::request('email'))) {
$this->_error(__('Invalid email'), 501);
} elseif (!is_numeric(core::request('id_product'))) {
$this->_error(__('Invalid product'), 501);
} else {
$product = new Model_Product(core::request('id_product'));
if ($product->loaded()) {
$user = Model_User::create_email(core::request('email'), core::request('name'));
$order = Model_Order::new_order($user, $product);
$order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id'), core::request('pay_date'), core::request('amount'), core::request('currency'), core::request('fee'));
//adding the notes
$order->notes = core::request('notes');
$order->save();
$this->rest_output(array('order' => self::get_order_array($order)));
} else {
$this->_error(__('Something went wrong'), 501);
}
}
} catch (Kohana_HTTP_Exception $khe) {
$this->_error($khe);
}
}
示例2: action_index
public function action_index()
{
$email = Core::post('email_subscribe');
if (Valid::email($email, TRUE)) {
/* find user and compare emails */
$obj_user = new Model_User();
$user = $obj_user->where('email', '=', $email)->limit(1)->find();
// case when user is not logged in.
// We create new user if he doesn't exists in DB
// and send him mail for ad created + new profile created
if (!$user->loaded()) {
$user = Model_User::create_email($email);
}
/* save this user to data base as subscriber */
$arr_cat = Core::post('category_subscribe');
// string in this case is returned as "int,int" so we need to format min/max price
$price = Core::post('price_subscribe');
if ($price = Core::post('price_subscribe')) {
$min_price = substr($price, '0', stripos($price, ','));
$max_price = substr($price, strrpos($price, ',') + 1);
} else {
//in case of mobile version
// jquery mobile have different slider, so we need to get data differently
$min_price = Core::post('price_subscribe-1');
$max_price = Core::post('price_subscribe-2');
}
//if categry is not selected, subscribe them for al, set category to 0 thats all...
if ($arr_cat === NULL) {
$arr_cat[] = 0;
}
// create entry table subscriber for each category selected
foreach ($arr_cat as $c => $id_value) {
$obj_subscribe = new Model_Subscribe();
$obj_subscribe->id_user = $user->id_user;
$obj_subscribe->id_category = $id_value;
$obj_subscribe->id_location = Core::post('location_subscribe');
$obj_subscribe->min_price = $min_price;
$obj_subscribe->max_price = $max_price;
try {
$obj_subscribe->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
Alert::set(Alert::SUCCESS, __('Thank you for subscribing'));
$this->redirect(Route::url('default'));
} else {
Alert::set(Alert::ALERT, __('Invalid Email'));
$this->redirect(Route::url('default'));
}
}
示例3: action_create
public function action_create()
{
$validation = Validation::factory($this->request->post())->rule('name', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email');
if ($validation->check()) {
$email = $this->_post_params['email'];
//check we have this email in the DB
$user = new Model_User();
$user = $user->where('email', '=', $email)->limit(1)->find();
if ($user->loaded()) {
$this->_error(__('User already exists'));
} else {
//creating the user
$user = Model_User::create_email($this->_post_params['email'], $this->_post_params['name'], isset($this->_post_params['password']) ? $this->_post_params['password'] : NULL);
//add custom fields
$save_cf = FALSE;
foreach ($this->_post_params as $custom_field => $value) {
if (strpos($custom_field, 'cf_') !== FALSE) {
$user->{$custom_field} = $value;
$save_cf = TRUE;
}
}
//saves the user only if there was CF
if ($save_cf === TRUE) {
$user->save();
}
//create the API token since he registered int he app
$res = $user->as_array();
$res['user_token'] = $user->api_token();
$this->rest_output(array('user' => $res));
}
} else {
$errors = '';
$e = $validation->errors('auth');
foreach ($e as $error) {
$errors .= $error . ' - ';
}
$this->_error($errors);
}
}
示例4: action_register
/**
* Simple register for user
*
*/
public function action_register()
{
$this->template->content = View::factory('pages/auth/register');
$this->template->content->msg = '';
//if user loged in redirect home
if (Auth::instance()->logged_in()) {
$this->redirect(Route::get('oc-panel')->uri());
} elseif ($this->request->post()) {
$validation = Validation::factory($this->request->post())->rule('name', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('password1', 'not_empty')->rule('password2', 'not_empty')->rule('password1', 'matches', array(':validation', 'password1', 'password2'));
if ($validation->check()) {
//posting data so try to remember password
if (CSRF::valid('register')) {
$email = core::post('email');
//check we have this email in the DB
$user = new Model_User();
$user = $user->where('email', '=', $email)->limit(1)->find();
if ($user->loaded()) {
Form::set_errors(array(__('User already exists')));
} else {
//creating the user
$user = Model_User::create_email($email, core::post('name'), core::post('password1'));
//login the user
Auth::instance()->login(core::post('email'), core::post('password1'));
Alert::set(Alert::SUCCESS, __('Welcome!'));
//login the user
$this->redirect(Core::post('auth_redirect', Route::url('oc-panel')));
}
}
} else {
$errors = $validation->errors('auth');
foreach ($errors as $error) {
Alert::set(Alert::ALERT, $error);
}
}
}
//template header
$this->template->title = __('Register new user');
$this->template->meta_description = __('Create a new profile at') . ' ' . Core::config('general.site_name');
}
示例5: action_register
/**
* Simple register for user
*
*/
public function action_register()
{
//validates captcha
if (Core::post('ajaxValidateCaptcha')) {
$this->auto_render = FALSE;
$this->template = View::factory('js');
if (captcha::check('register', TRUE)) {
$this->template->content = 'true';
} else {
$this->template->content = 'false';
}
return;
}
$this->template->meta_description = __('Create a new profile at') . ' ' . core::config('general.site_name');
$this->template->content = View::factory('pages/auth/register');
$this->template->content->msg = '';
//if user loged in redirect home
if (Auth::instance()->logged_in()) {
$this->redirect(Route::get('oc-panel')->uri());
} elseif ($this->request->post()) {
if (captcha::check('register')) {
$validation = Validation::factory($this->request->post())->rule('name', 'not_empty')->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('password1', 'not_empty')->rule('password2', 'not_empty')->rule('password1', 'matches', array(':validation', 'password1', 'password2'));
if (core::post('cf_vatnumber') and core::post('cf_vatcountry')) {
if (!euvat::verify_vies(core::post('cf_vatnumber'), core::post('cf_vatcountry'))) {
Alert::set(Alert::ERROR, __('Invalid EU Vat Number, please verify number and country match'));
$this->redirect(Route::url('oc-panel', array('controller' => 'auth', 'action' => 'register')));
}
}
if ($validation->check()) {
//posting data so try to remember password
if (CSRF::valid('register')) {
$email = core::post('email');
//check we have this email in the DB
$user = new Model_User();
$user = $user->where('email', '=', $email)->limit(1)->find();
if ($user->loaded()) {
Form::set_errors(array(__('User already exists')));
} else {
//creating the user
$user = Model_User::create_email($email, core::post('name'), core::post('password1'));
//add custom fields
$save_cf = FALSE;
foreach ($this->request->post() as $custom_field => $value) {
if (strpos($custom_field, 'cf_') !== FALSE) {
$user->{$custom_field} = $value;
$save_cf = TRUE;
}
}
//saves the user only if there was CF
if ($save_cf === TRUE) {
$user->save();
}
//login the user
Auth::instance()->login(core::post('email'), core::post('password1'));
Alert::set(Alert::SUCCESS, __('Welcome!'));
//login the user
$this->redirect(Core::post('auth_redirect', Route::url('oc-panel')));
}
}
} else {
$errors = $validation->errors('auth');
foreach ($errors as $error) {
Alert::set(Alert::ALERT, $error);
}
}
} else {
Alert::set(Alert::ALERT, __('Captcha is not correct'));
}
}
//template header
$this->template->title = __('Register new user');
}
示例6: action_index
//.........这里部分代码省略.........
} else {
$selected_category->where('seoname', '=', core::request('category'))->limit(1)->find();
}
if ($selected_category->loaded()) {
$id_category = $selected_category->id_category;
}
}
$id_location = NULL;
$selected_location = new Model_Location();
//if theres a location by post or by get
if (Core::request('location') !== NULL) {
if (is_numeric(Core::request('location'))) {
$selected_location->where('id_location', '=', core::request('location'))->limit(1)->find();
} else {
$selected_location->where('seoname', '=', core::request('location'))->limit(1)->find();
}
if ($selected_location->loaded()) {
$id_location = $selected_location->id_location;
}
}
//render view publish new
$this->template->content = View::factory('pages/ad/new', array('categories' => $categories, 'order_categories' => $order_categories, 'order_parent_deep' => $order_parent_deep, 'locations' => $locations, 'order_locations' => $order_locations, 'loc_parent_deep' => $loc_parent_deep, 'form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all()));
if ($this->request->post()) {
if (captcha::check('publish_new')) {
$data = $this->request->post();
$validation = Validation::factory($data);
//validate location since its optional
if (core::config('advertisement.location')) {
if (count($locations) > 1) {
$validation = $validation->rule('location', 'not_empty')->rule('location', 'digit');
}
}
//user is not logged in validate input
if (!Auth::instance()->logged_in()) {
$validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145));
}
if ($validation->check()) {
// User detection, if doesnt exists create
if (!Auth::instance()->logged_in()) {
$user = Model_User::create_email(core::post('email'), core::post('name'));
} else {
$user = Auth::instance()->get_user();
}
//to make it backward compatible with older themes: UGLY!!
if (isset($data['category']) and is_numeric($data['category'])) {
$data['id_category'] = $data['category'];
unset($data['category']);
}
if (isset($data['location']) and is_numeric($data['location'])) {
$data['id_location'] = $data['location'];
unset($data['location']);
}
//lets create!!
$return = Model_Ad::new_ad($data, $user);
//there was an error on the validation
if (isset($return['validation_errors']) and is_array($return['validation_errors'])) {
foreach ($return['validation_errors'] as $f => $err) {
Alert::set(Alert::ALERT, $err);
}
} elseif (isset($return['error'])) {
Alert::set($return['error_type'], $return['error']);
} elseif (isset($return['message']) and isset($return['ad'])) {
$new_ad = $return['ad'];
// IMAGE UPLOAD
$filename = NULL;
for ($i = 0; $i < core::config('advertisement.num_images'); $i++) {
if (isset($_FILES['image' . $i])) {
$filename = $new_ad->save_image($_FILES['image' . $i]);
}
if ($filename) {
$new_ad->has_images++;
}
}
//since theres images save the ad again...
if ($new_ad->has_images > 0) {
try {
$new_ad->save();
} catch (Exception $e) {
throw HTTP_Exception::factory(500, $e->getMessage());
}
}
Alert::set(Alert::SUCCESS, $return['message']);
//redirect user
if (isset($return['checkout_url']) and !empty($return['checkout_url'])) {
$this->redirect($return['checkout_url']);
} else {
$this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad)));
}
}
} else {
$errors = $validation->errors('ad');
foreach ($errors as $f => $err) {
Alert::set(Alert::ALERT, $err);
}
}
} else {
Alert::set(Alert::ALERT, __('Captcha is not correct'));
}
}
}
示例7: migrate
/**
* does the DB migration
* @param pointer $db
* @param string $pf db_prefix
*/
private function migrate($db, $pf)
{
set_time_limit(0);
$db_config = core::config('database.default');
$prefix = $db_config['table_prefix'];
//connect DB original/to where we migrate
$dbo = Database::instance('default');
//oc_accounts --> oc_users
$users_map = array();
$accounts = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'accounts`');
foreach ($accounts as $account) {
$user = new Model_User();
$user->where('email', '=', $account['email'])->limit(1)->find();
if (!$user->loaded()) {
$user->name = $account['name'];
$user->email = $account['email'];
$user->password = $account['password'];
$user->created = $account['createdDate'];
$user->last_modified = $account['lastModifiedDate'];
$user->last_login = $account['lastSigninDate'];
$user->status = $account['active'];
$user->id_role = 1;
$user->seoname = $user->gen_seo_title($user->name);
$user->save();
}
$users_map[$account['email']] = $user->id_user;
}
//categories --> categories
$categories_map = array(0 => 1);
$categories = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'categories` ORDER BY `idCategoryParent` ASC');
foreach ($categories as $category) {
$cat = new Model_Category();
$cat->name = $category['name'];
$cat->order = $category['order'];
$cat->created = $category['created'];
$cat->seoname = $category['friendlyName'];
$cat->price = $category['price'];
$cat->description = substr($category['description'], 0, 250);
$cat->parent_deep = $category['idCategoryParent'] > 0 ? 1 : 0;
//there's only 1 deep
$cat->id_category_parent = isset($categories_map[$category['idCategoryParent']]) ? $categories_map[$category['idCategoryParent']] : 1;
$cat->save();
//we save old_id stores the new ID, so later we know the category parent, and to changes the ADS category id
$categories_map[$category['idCategory']] = $cat->id_category;
}
//locations --> locations
$locations_map = array(0 => 1);
$locations = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'locations` ORDER BY `idLocationParent` ASC');
foreach ($locations as $location) {
$loc = new Model_Location();
$loc->name = $location['name'];
$loc->seoname = $location['friendlyName'];
$loc->parent_deep = $location['idLocationParent'] > 0 ? 1 : 0;
//there's only 1 deep
$loc->id_location_parent = isset($locations_map[$location['idLocationParent']]) ? $locations_map[$location['idLocationParent']] : 1;
$loc->save();
//we save old_id stores the new ID, so later we know the location parent, and to changes the ADS location id
$locations_map[$location['idLocation']] = $loc->id_location;
}
//posts --> ads
$ads_map = array();
$ads = $db->query(Database::SELECT, 'SELECT * FROM `' . $pf . 'posts`');
foreach ($ads as $a) {
if (Valid::email($a['email'])) {
//gettin the id_user
if (isset($users_map[$a['email']])) {
$id_user = $users_map[$a['email']];
} else {
$user = Model_User::create_email($a['email'], $a['name']);
$id_user = $user->id_user;
}
$ad = new Model_Ad();
$ad->id_ad = $a['idPost'];
//so images still work
$ad->id_user = $id_user;
$ad->id_category = isset($categories_map[$a['idCategory']]) ? $categories_map[$a['idCategory']] : 1;
$ad->id_location = isset($locations_map[$a['idLocation']]) ? $locations_map[$a['idLocation']] : 1;
$ad->title = $a['title'];
$ad->seotitle = $ad->gen_seo_title($a['title']);
$ad->description = !empty($a['description']) ? Text::html2bb($a['description']) : $a['title'];
$ad->address = $a['place'];
$ad->price = $a['price'];
$ad->phone = $a['phone'];
$ad->has_images = $a['hasImages'];
$ad->ip_address = ip2long($a['ip']);
$ad->created = $a['insertDate'];
$ad->published = $ad->created;
//Status migration...big mess!
if ($a['isAvailable'] == 0 and $a['isConfirmed'] == 0) {
$ad->status = Model_Ad::STATUS_NOPUBLISHED;
} elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 0) {
$ad->status = Model_Ad::STATUS_NOPUBLISHED;
} elseif ($a['isAvailable'] == 1 and $a['isConfirmed'] == 1) {
$ad->status = Model_Ad::STATUS_PUBLISHED;
} elseif ($a['isAvailable'] == 0 and $a['isConfirmed'] == 1) {
//.........这里部分代码省略.........
示例8: action_index
//.........这里部分代码省略.........
//if theres a category by post or by get
if (Core::request('category') !== NULL) {
if (is_numeric(Core::request('category'))) {
$selected_category->where('id_category', '=', core::request('category'))->limit(1)->find();
} else {
$selected_category->where('seoname', '=', core::request('category'))->limit(1)->find();
}
if ($selected_category->loaded()) {
$id_category = $selected_category->id_category;
}
}
$id_location = NULL;
$selected_location = new Model_Location();
//if theres a location by post or by get
if (Core::request('location') !== NULL) {
if (is_numeric(Core::request('location'))) {
$selected_location->where('id_location', '=', core::request('location'))->limit(1)->find();
} else {
$selected_location->where('seoname', '=', core::request('location'))->limit(1)->find();
}
if ($selected_location->loaded()) {
$id_location = $selected_location->id_location;
}
}
//render view publish new
$this->template->content = View::factory('pages/ad/new', array('form_show' => $form_show, 'id_category' => $id_category, 'selected_category' => $selected_category, 'id_location' => $id_location, 'selected_location' => $selected_location, 'fields' => Model_Field::get_all()));
if ($this->request->post()) {
if (captcha::check('publish_new')) {
$data = $this->request->post();
$validation = Validation::factory($data);
//validate location since its optional
if (core::config('advertisement.location')) {
if ($locations->count_all() > 1) {
$validation = $validation->rule('location', 'not_empty')->rule('location', 'digit');
}
}
//user is not logged in validate input
if (!Auth::instance()->logged_in()) {
$validation = $validation->rule('email', 'not_empty')->rule('email', 'email')->rule('email', 'email_domain')->rule('name', 'not_empty')->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 145));
}
// Optional banned words validation
if (core::config('advertisement.validate_banned_words')) {
$validation = $validation->rule('title', 'no_banned_words');
$validation = $validation->rule('description', 'no_banned_words');
}
if ($validation->check()) {
// User detection, if doesnt exists create
if (!Auth::instance()->logged_in()) {
$user = Model_User::create_email(core::post('email'), core::post('name'));
} else {
$user = Auth::instance()->get_user();
}
//to make it backward compatible with older themes: UGLY!!
if (isset($data['category']) and is_numeric($data['category'])) {
$data['id_category'] = $data['category'];
unset($data['category']);
}
if (isset($data['location']) and is_numeric($data['location'])) {
$data['id_location'] = $data['location'];
unset($data['location']);
}
//lets create!!
$return = Model_Ad::new_ad($data, $user);
//there was an error on the validation
if (isset($return['validation_errors']) and is_array($return['validation_errors'])) {
foreach ($return['validation_errors'] as $f => $err) {
Alert::set(Alert::ALERT, $err);
}
} elseif (isset($return['error'])) {
Alert::set($return['error_type'], $return['error']);
} elseif (isset($return['message']) and isset($return['ad'])) {
$new_ad = $return['ad'];
// IMAGE UPLOAD
$filename = NULL;
for ($i = 0; $i < core::config('advertisement.num_images'); $i++) {
if (Core::post('base64_image' . $i)) {
$filename = $new_ad->save_base64_image(Core::post('base64_image' . $i));
} elseif (isset($_FILES['image' . $i])) {
$filename = $new_ad->save_image($_FILES['image' . $i]);
}
}
Alert::set(Alert::SUCCESS, $return['message']);
//redirect user
if (isset($return['checkout_url']) and !empty($return['checkout_url'])) {
$this->redirect($return['checkout_url']);
} else {
$this->redirect(Route::url('default', array('action' => 'thanks', 'controller' => 'ad', 'id' => $new_ad->id_ad)));
}
}
} else {
$errors = $validation->errors('ad');
foreach ($errors as $f => $err) {
Alert::set(Alert::ALERT, $err);
}
}
} else {
Alert::set(Alert::ALERT, __('Captcha is not correct'));
}
}
}
示例9: action_import
public function action_import()
{
if ($this->request->post()) {
ini_set('auto_detect_line_endings', true);
$csv = $_FILES['file_source']['tmp_name'];
if (($handle = fopen($csv, "r")) !== FALSE) {
$i = 0;
while (($data = fgetcsv($handle, 0, ";")) !== false) {
//avoid first line
if ($i != 0) {
list($email, $pay_date, $product_seotitle, $amount, $currency) = $data;
$pay_date = Date::from_format($pay_date, 'd/m/yy', 'Y-m-d H:i:s');
$user = Model_User::create_email($email, substr($email, 0, strpos($email, '@')));
$product = new Model_Product();
$product->where('seotitle', '=', $product_seotitle)->limit(1)->find();
if ($product->loaded()) {
$order = Model_Order::new_order($user, $product);
$order->confirm_payment('import', NULL, $pay_date, $amount, $currency);
}
}
$i++;
}
}
fclose($handle);
//redirect to orders
Alert::set(Alert::SUCCESS, __('Import correct'));
$this->redirect(Route::url('oc-panel', array('controller' => 'order', 'action' => 'index')));
}
//template header
$this->template->title = __('Import Orders');
Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Import Orders')));
$this->template->content = View::factory('oc-panel/pages/order/import');
}