public function emailSubmit() { $f3 = \Base::instance(); $email = $this->input->get('new_email', null, 'string'); $data = array('change_email' => array('email' => $email, 'token' => (string) new \MongoId(), 'created' => \Dsc\Mongo\Metastamp::getDate('now'))); // TODO Validate that it is an email if (empty($email)) { \Dsc\System::addMessage('Invalid Email.', 'error'); $f3->reroute('/user/change-email'); return; } // Verify whether or not the email address is already registered if (\Users\Models\Users::emailExists($email)) { \Dsc\System::addMessage('Email address already registered.', 'error'); $f3->reroute('/user/change-email'); return; } $user = $this->getIdentity(); $user->bind($data); try { $user->save()->sendEmailChangeEmailConfirmation(); } catch (\Exception $e) { \Dsc\System::addMessage('Email submission failed.', 'error'); \Dsc\System::addMessage($e->getMessage(), 'error'); $f3->reroute('/user/change-email'); return; } \Dsc\System::addMessage('Email change request submitted. Please check your inbox for a verification email from us.'); $f3->reroute('/user/change-email/verify'); }
public static function fetchForEmail($email) { $actor = new static(); $user = \Users\Models\Users::emailExists($email); if (!empty($user->id)) { $actor->load(array('user_id' => $user->id)); $actor->user_id = $user->id; $actor->name = $user->email; } else { $actor->load(array('name' => $email)); $actor->name = $email; } if (empty($actor->id)) { $actor->is_excluded = false; $actor->is_excluded_last_checked = date('Y-m-d', strtotime('today')); $actor->is_bot = false; $actor->is_bot_last_checked = date('Y-m-d', strtotime('today')); $actor->save(); } if ($actor->is_bot_last_checked < date('Y-m-d', strtotime('today')) || $actor->is_excluded_last_checked < date('Y-m-d', strtotime('today'))) { $actor->is_excluded_last_checked = date('Y-m-d', strtotime('today')); $actor->is_bot_last_checked = date('Y-m-d', strtotime('today')); $actor->store(); } return $actor; }
public function register() { $f3 = \Base::instance(); $checkout_method = strtolower($this->input->get('checkout_method', null, 'alnum')); switch ($checkout_method) { // if $checkout_method == guest // store email in cart object and then continue // create a guest mongoid case "guest": $real_email = trim(strtolower($this->input->get('email_address', null, 'string'))); if (\Users\Models\Users::emailExists($real_email)) { \Dsc\System::addMessage('This email is already registered. Please login to continue. <a href="./user/forgot-password">If necessary, you can recover your password here.</a>', 'error'); $this->app->reroute('/shop/checkout'); return; } $mongo_id = (string) new \MongoId(); $email = 'guest-' . $mongo_id . '@' . $mongo_id . '.' . $mongo_id; $password = \Users\Models\Users::generateRandomString(); $data = array('first_name' => 'Guest', 'last_name' => 'User', 'email' => $email, 'guest_email' => $real_email, 'new_password' => $password, 'confirm_new_password' => $password); $user = (new \Users\Models\Users())->bind($data); try { // this will handle other validations, such as username uniqueness, etc $user->guest = true; $user->active = false; $user->save(); } catch (\Exception $e) { \Dsc\System::addMessage('Could not create guest account', 'error'); \Dsc\System::addMessage($e->getMessage(), 'error'); \Dsc\System::instance()->setUserState('shop.checkout.register.flash_filled', true); $flash = \Dsc\Flash::instance(); $flash->store(array()); $this->app->reroute('/shop/checkout'); return; } // if we have reached here, then all is right with the form $flash = \Dsc\Flash::instance(); $flash->store(array()); // login the user, trigger Listeners \Dsc\System::instance()->get('auth')->login($user); $this->app->reroute('/shop/checkout'); break; // if $checkout_method == register // validate data // create user // redirect back to checkout // if $checkout_method == register // validate data // create user // redirect back to checkout case "register": $email = trim(strtolower($this->input->get('email_address', null, 'string'))); $data = array('first_name' => $this->input->get('first_name', null, 'string'), 'last_name' => $this->input->get('last_name', null, 'string'), 'email' => $email, 'new_password' => $this->input->get('new_password', null, 'string'), 'confirm_new_password' => $this->input->get('confirm_new_password', null, 'string')); $user = (new \Users\Models\Users())->bind($data); // Check if the email already exists and give a custom message if so if (!empty($user->email) && ($existing = $user->emailExists($user->email))) { if (empty($user->id) || $user->id != $existing->id) { \Dsc\System::addMessage('This email is already registered.', 'error'); \Dsc\System::instance()->setUserState('shop.checkout.register.flash_filled', true); $flash = \Dsc\Flash::instance(); $flash->store($user->cast()); $this->app->reroute('/shop/checkout'); return; } } try { // this will handle other validations, such as username uniqueness, etc $settings = \Users\Models\Settings::fetch(); $registration_action = $settings->{'general.registration.action'}; switch ($registration_action) { case "auto_login": $user->active = true; $user->save(); break; case "auto_login_with_validation": $user->active = false; $user->save(); $user->sendEmailValidatingEmailAddress(); break; default: $user->active = false; $user->save(); $user->sendEmailValidatingEmailAddress(); break; } } catch (\Exception $e) { \Dsc\System::addMessage('Could not create account.', 'error'); \Dsc\System::addMessage($e->getMessage(), 'error'); \Dsc\System::instance()->setUserState('shop.checkout.register.flash_filled', true); $flash = \Dsc\Flash::instance(); $flash->store($user->cast()); $f3->reroute('/shop/checkout'); return; } // if we have reached here, then all is right with the form $flash = \Dsc\Flash::instance(); $flash->store(array()); // login the user, trigger Listeners \Dsc\System::instance()->get('auth')->login($user); $this->app->reroute('/shop/checkout'); break; // if $checkout_method something else, // add message? // redirect back to checkout // if $checkout_method something else, // add message? // redirect back to checkout default: \Dsc\System::addMessage('Invalid Checkout Method', 'error'); $this->app->reroute('/shop/checkout'); break; } }