Inheritance: extends Mode\Model
 protected function getLoginAttr()
 {
     if (is_null($this->loginAttr)) {
         $this->loginAttr = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
     }
     return $this->loginAttr;
 }
Example #2
0
 /**
  * Display username field if settings permit
  */
 public function formExtendFields($form)
 {
     /*
      * Show the username field if it is configured for use
      */
     if (UserSettings::get('login_attribute') == UserSettings::LOGIN_USERNAME && array_key_exists('username', $form->getFields())) {
         $form->getField('username')->hidden = false;
     }
 }
Example #3
0
 /**
  * Display username field if settings permit
  */
 protected function formExtendFields($form)
 {
     $loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
     if ($loginAttribute != UserSettings::LOGIN_USERNAME) {
         return;
     }
     if (array_key_exists('username', $form->getFields())) {
         $form->getField('username')->hidden = false;
     }
 }
Example #4
0
 public function setDefaults()
 {
     if (!$this->country_id) {
         $this->country_id = UserSettings::get('default_country', 1);
     }
     if (!$this->state_id) {
         $this->state_id = UserSettings::get('default_state', 1);
     }
     if (!$this->template_id) {
         $this->template_id = InvoiceSettings::get('default_invoice_template', 1);
     }
 }
Example #5
0
 /**
  * Api function for add new user
  * 
  * @return Response
  */
 public function postUser()
 {
     $data = post();
     /* Validator request params */
     $valids = Validator::make($data, ['name' => 'required', 'email' => 'required|email|between:2,64', 'password' => 'required|min:2', 'password_confirmation' => 'required|confirmed']);
     if ($valids->fails()) {
         return SNSContactsHelper::getErrorMsg($valids->messages());
     }
     $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
     $user = Auth::register($data, $automaticActivation);
     /*
      * Automatically activated or not required, log the user in
      */
     if ($automaticActivation || !$requireActivation) {
         Auth::login($user);
     }
     return SNSContactsHelper::getSuccess($user);
 }
Example #6
0
 public function postSession()
 {
     $data = post();
     $rules = ['password' => 'required|min:2'];
     $loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
     if ($loginAttribute == UserSettings::LOGIN_USERNAME) {
         $rules['login'] = '******';
     } else {
         $rules['login'] = '******';
     }
     if (!in_array('login', $data)) {
         $data['login'] = post('username', post('email'));
     }
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         throw new ValidationException($validation);
     }
     /*
      * Authenticate user
      */
     $user = Auth::authenticate(['login' => array_get($data, 'login'), 'password' => array_get($data, 'password')], true);
     return Response::json(response_message(200, $user));
 }
Example #7
0
 /**
  * Register the user
  */
 public function onRegister()
 {
     try {
         if (!UserSettings::get('allow_registration', true)) {
             throw new ApplicationException(Lang::get('rainlab.user::lang.account.registration_disabled'));
         }
         /*
          * Validate input
          */
         $data = post();
         if (!array_key_exists('password_confirmation', $data)) {
             $data['password_confirmation'] = post('password');
         }
         $rules = ['email' => 'required|email|between:6,255', 'password' => 'required|between:4,255|confirmed'];
         if ($this->loginAttribute() == UserSettings::LOGIN_USERNAME) {
             $rules['username'] = '******';
         }
         $validation = Validator::make($data, $rules);
         if ($validation->fails()) {
             throw new ValidationException($validation);
         }
         /*
          * Register user
          */
         $requireActivation = UserSettings::get('require_activation', true);
         $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
         $userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER;
         $user = Auth::register($data, $automaticActivation);
         /*
          * Activation is by the user, send the email
          */
         if ($userActivation) {
             $this->sendActivationEmail($user);
             Flash::success(Lang::get('rainlab.user::lang.account.activation_email_sent'));
         }
         /*
          * Automatically activated or not required, log the user in
          */
         if ($automaticActivation || !$requireActivation) {
             Auth::login($user);
         }
         /*
          * Redirect to the intended page after successful sign in
          */
         $redirectUrl = $this->pageUrl($this->property('redirect')) ?: $this->property('redirect');
         if ($redirectUrl = post('redirect', $redirectUrl)) {
             return Redirect::intended($redirectUrl);
         }
     } catch (Exception $ex) {
         if (Request::ajax()) {
             throw $ex;
         } else {
             Flash::error($ex->getMessage());
         }
     }
 }
Example #8
0
 /**
  * Register the user
  */
 public function onRegister()
 {
     /*
      * Validate input
      */
     $data = post();
     if (!array_key_exists('password_confirmation', Input::all())) {
         $data['password_confirmation'] = post('password');
     }
     $rules = ['email' => 'required|email|between:2,64', 'password' => 'required|min:2'];
     $loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
     if ($loginAttribute == UserSettings::LOGIN_USERNAME) {
         $rules['username'] = '******';
     }
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         throw new ValidationException($validation);
     }
     /*
      * Register user
      */
     $requireActivation = UserSettings::get('require_activation', true);
     $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
     $userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER;
     $user = Auth::register($data, $automaticActivation);
     /*
      * Activation is by the user, send the email
      */
     if ($userActivation) {
         $this->sendActivationEmail($user);
     }
     /*
      * Automatically activated or not required, log the user in
      */
     if ($automaticActivation || !$requireActivation) {
         Auth::login($user);
     }
     /*
      * Redirect to the intended page after successful sign in
      */
     $redirectUrl = $this->pageUrl($this->property('redirect'));
     if ($redirectUrl = post('redirect', $redirectUrl)) {
         return Redirect::intended($redirectUrl);
     }
 }
Example #9
0
 public function init()
 {
     $this->useThrottle = UserSettings::get('use_throttle', $this->useThrottle);
     $this->requireActivation = UserSettings::get('require_activation', $this->requireActivation);
     parent::init();
 }
Example #10
0
 /**
  * Returns the name for the user's login.
  * @return string
  */
 public function getLoginName()
 {
     if (static::$loginAttribute !== null) {
         return static::$loginAttribute;
     }
     return static::$loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
 }
Example #11
0
 /**
  * Sends the confirmation email to a user, after activating
  * @param  string $code
  * @return void
  */
 public function attemptActivation($code)
 {
     $result = parent::attemptActivation($code);
     if ($result === false) {
         return false;
     }
     if (!($mailTemplate = UserSettings::get('welcome_template'))) {
         return;
     }
     $data = ['name' => $this->name, 'email' => $this->email];
     Mail::send($mailTemplate, $data, function ($message) {
         $message->to($this->email, $this->name);
     });
 }
Example #12
0
 public static function sendEmailAfterRegister($name, $email)
 {
     if (!$name || !$email) {
         return false;
     }
     if (!($mailTemplate = UserSettings::get('welcome_template'))) {
         return;
     }
     self::$name = $name;
     self::$email = $email;
     $data = ['name' => $name, 'email' => $email];
     Mail::send($mailTemplate, $data, function ($message) {
         $message->to(self::$email, self::$name);
     });
 }
Example #13
0
 /**
  * Sends the confirmation email to a user, after activating.
  * @param  string $code
  * @return void
  */
 public function attemptActivation($code)
 {
     $result = parent::attemptActivation($code);
     if ($result === false) {
         return false;
     }
     if ($mailTemplate = UserSettings::get('welcome_template')) {
         Mail::sendTo($this, $mailTemplate, ['name' => $this->name, 'email' => $this->email]);
     }
     return true;
 }
Example #14
0
 public static function getDefault()
 {
     return static::find(Settings::get('default_state', 1));
 }
Example #15
0
 /**
  * Register a user
  *
  * @param array $data
  * An array of attributes to register a user.
  * Any fields that are not properties on the user object
  * Will be applied to the Usermeta object
  *
  * @param array $rules
  * A set of validation rules to validate against
  * see http://laravel.com/docs/5.1/validation
  *
  * @return User $user
  * return the user object after registration
  */
 public static function register($data, $rules = [])
 {
     $rules += ['first_name' => 'required|min:2', 'last_name' => 'required|min:2', 'email' => 'required|email|between:2,64', 'password' => 'required|min:6', 'password_confirmation' => 'required|min:6'];
     Event::fire('auth.preRegister', [$data, $rules]);
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         throw new ValidationException($validation);
     }
     /*
      * Register user
      */
     $requireActivation = UserSettings::get('require_activation', true);
     $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
     $userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER;
     /*
      * Data altercations
      */
     $data['first_name'] = ucwords($data['first_name']);
     $data['last_name'] = ucwords($data['last_name']);
     $data['birth_date'] = UserExtend::parseBirthdate($data['birthday']);
     $data['phone'] = UserExtend::parsePhone($data['phone']);
     $data['email_optin'] = isset($data['email_optin']) ? $data['email_optin'] : false;
     // Split the data into whats required for the user and usermeta models
     $userData = ['name' => $data['first_name'] . ' ' . $data['last_name'], 'password' => $data['password'], 'password_confirmation' => $data['password_confirmation'], 'email' => $data['email'], 'street_addr' => $data['street_addr'], 'city' => $data['city'], 'state' => $data['state'], 'zip' => $data['zip'], 'phone' => $data['phone']];
     $user = Auth::register($userData, $automaticActivation);
     // Save user metadata
     $usermeta = Usermeta::create($data);
     $user->metadata()->save($usermeta);
     if (isset($data['avatar'])) {
         UserExtend::uploadAvatar($user, $data['avatar']);
     }
     /*
      * Activation is by the user, send the email
      */
     if ($userActivation) {
         $this->sendActivationEmail($user);
     }
     /*
      * Automatically activated or not required, log the user in
      */
     if ($automaticActivation || !$requireActivation) {
         Auth::login($user);
     }
     if ($user) {
         /*
          * Fire event that user has registered
          */
         Event::fire('auth.register', [$user]);
         return $user;
     }
     return false;
 }
Example #16
0
 public static function onSignin()
 {
     /*
      * Validate input
      */
     $data = post();
     $rules = ['password' => 'required|min:2'];
     $loginAttribute = UserSettings::get('login_attribute', UserSettings::LOGIN_EMAIL);
     if ($loginAttribute == UserSettings::LOGIN_USERNAME) {
         $rules['login'] = '******';
     } else {
         $rules['login'] = '******';
     }
     if (!in_array('login', $data)) {
         $data['login'] = post('username', post('email'));
     }
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         throw new ValidationException($validation);
     }
     /*
      * Authenticate user
      */
     try {
         $user = Auth::authenticate(['login' => array_get($data, 'login'), 'password' => array_get($data, 'password')], true);
     } catch (Exception $e) {
         throw $e;
     }
 }