Signs user up.

@return UserModel|null the saved model or null if saving fails
490599
public function signup()
    {
        if (!$this->validate()) {
            return null;
        }

        $this->user = new UserModel();
        $this->user->setAttributes($this->attributes);
        $this->user->setPassword($this->password);
        $this->user->setLastLogin(time());
        $this->user->generateAuthKey();

        return $this->user->save() ? $this->user : null;
    }
441713
public function getUserSessionToken()
    {
        if (($u = $this->getUserLoggedIn()) == null) {
            return null;
        }

        return isset($_SESSION['model-user-library-session-token']) ? $_SESSION['model-user-library-session-token'] : $_SESSION['model-user-library-session-token'] = $u->getUserToken();
    }
281477
public function getLoggedUser()
    {
        $credentials = $this->storage->getLoggedUser();

        return is_array($credentials) ? new User($credentials) : null;
    }
754964
public function actionSignup()
    {
        $this->layout = '@vendor/cubiclab/admin-cube/views/layouts/signin';

        $user = new User(['scenario' => 'register']);

        // if register action is triggered
        if ($user->load(Yii::$app->request->post())) {
            if ($user->validate()) {

                if ($user->save(false)) {
                    Yii::$app->user->login($user);
                    Yii::$app->session->setFlash('success', 'Register success');

                    return $this->goHome();
                } else {
                    Yii::$app->session->setFlash('danger', 'Register error');
                    return $this->refresh();
                }
            } elseif (Yii::$app->request->isAjax) {
                Yii::$app->response->format = Response::FORMAT_JSON;
                return ActiveForm::validate($user);
            }
        }

        // render view
        return $this->render(
            'signup',
            [
                'user' => $user
            ]
        );
    }
1024112
public function getUsername()
    {
        if (!$this->hasEnabledUsername()) {
            return null;
        }
        $usernameClass = $this->usernameClass;
        $noInit = $usernameClass::buildNoInitModel();
        /* @var $noInit Username */
        return $this->hasOne($usernameClass, [$noInit->createdByAttribute => $this->guidAttribute]);
    }
1160086
public function postSignup()
    {
        /************TEMP VARIABLE************/
        /*
         * 0 - Disabled
         * 1 - Enabled and no activation
         * 2 - User activation
         * 3 - Admin activation
         */

        $signupStatus = \Base::getSetting('USER_REGISTRATION');
        /************TEMP VARIABLE************/

        $signupEnabled = $signupStatus != 0;
        $userActivation = $signupStatus == 2;
        $adminActivation = $signupStatus == 3;

        if (!$signupEnabled)
            return Redirect::to(URL::previous())->withInput()->with('error', Lang::get('base.auth.account.registration_disabled'));

        $rules = array();

        // Declare the rules for the form validation
        foreach(Sentinel::createModel()->getRegisterFields() as $fieldid => $field)
            $rules[$fieldid] = $field['validator'];

        $rules['g-recaptcha-response'] = 'required';

        // Create a new validator instance from our validation rules
        $validator = Validator::make(Input::all(), $rules);

        $err = false;

        // If validation fails, we'll exit the operation now.
        if ($validator->fails() || ($err = $this->captchaCheck()) == false) {
            if ($err)
                return Redirect::to(URL::previous())->withInput()->withErrors(['g-recaptcha-response' => Lang::get('base.captcha.error')]);

            // Ooops.. something went wrong
            return Redirect::to(URL::previous())->withInput()->withErrors($validator);
        }

        try {
            $data = array();

            // Set the data to the user from the User class
            foreach(Sentinel::createModel()->getRegisterFields() as $fieldid => $field)
                $data[$fieldid] = Input::get($fieldid);

            // Set the standard data to the user
            $data['ip'] = Request::getClientIP();
            $data['status'] = 0;
            $data['staff'] = 0;
            if ($data['birthday'] != null)
                $data['birthday'] = \Carbon\Carbon::createFromFormat('d/m/Y', $data['birthday']);

            // Find the user if it exists and needs to be created
            $user = Sentinel::getUserRepository()->findByCredentials(['email' => Input::get('email')]);

            if ($user != null)
            {
                // Update the temporary user to the new one
                if (Sentinel::validForUpdate($data, ['email' => Input::get('email')])) {
                    $testing = Sentinel::createModel()->getRegisterFields();
                    $user = Sentinel::findById($user->id);

                    foreach($data as $fieldid => $field)
                        if (!isset($testing[$fieldid]) || $testing[$fieldid]['save'] == true)
                            $user[$fieldid] = $field;

                    $user['password'] = bcrypt($user['password']);
                    Sentinel::update($user, ['email' => Input::get('email')]);
                }
                else
                    return Redirect::to(URL::previous())->withInput()->with('error', Lang::get('base.auth.account.registration_failed'));
            }
            // Register the user
            else
                $user = Sentinel::register($data, false);

            // If the user needs to activate the account send him an email
            if ($userActivation)
            {
                $activation = Activation::create($user);

                // Data to be used on the email view
                $data = array(
                    'user'          => $user,
                    'activationUrl' => URL::route('activate', [$user->id, $activation->code]),
                );

                // Send the activation code through email
                Mail::queue('emails.auth.register-activate', $data, function ($m) use ($user) {
                    $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                    $m->subject(Lang::get('base.mails.welcome') . ' ' . $user->first_name);
                });
            }

            // If the administrator needs to activate the account send the user a warning saying that
            if ($adminActivation)
            {
                Mail::queue('emails.auth.register-admin-activate', ['user' => $user], function ($m) use ($user) {
                    $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                    $m->subject(Lang::get('base.mails.welcome') . ' ' . $user->first_name);
                });
            }

            // Log the user in
            if (!$adminActivation && !$userActivation)
            {
                $activation = Activation::create($user);

                if (Activation::complete($user, $activation->code)) {
                    Sentinel::login($user, false);

                    Mail::queue('emails.auth.activated', ['user' => $user], function ($m) use ($user) {
                        $m->to($user->email, $user->first_name . ' ' . $user->last_name);
                        $m->subject(Lang::get('base.mails.welcome') . ' ' . $user->first_name);
                    });
                }
            }

            Base::Log('New account registred for ' . $user->username . ' (' . $user->first_name . ' ' . $user->last_name . ') from IP ' . Request::ip() );

            // Redirect to the home page with success menu
            return Redirect::to("login")->with('success', Lang::get('base.auth.signup.success') . $adminActivation ? Lang::get('base.auth.signup.admin') : $userActivation ? Lang::get('base.auth.signup.self') : Lang::get('base.auth.signup.ready'));
        } catch (UserExistsException $e) {
            $this->messageBag->add('email', Lang::get('base.auth.account.already_exists'));
        }

        Base::Log('New account registration attempt from IP ' . Request::ip() );

        // Ooops.. something went wrong
        return Redirect::back()->withInput()->withErrors($this->messageBag);
    }
949769
protected function getUserId()
    {
        if (property_exists($this, 'userKey'))
        {
            $userKey = $this->userKey;

            return $this->$userKey;
        }

        if ( ! is_null($this->user_id))
        {
            return $this->user_id;
        }

        return null;
    }
242408
public function save()
    {
        if ($this->validate()) {
            $class = $this->className;
            if ($this->_item === null) {
                $this->_item = new $class();
                $isNew = true;
            } else {
                $isNew = false;
                $oldName = $this->_item->name;
            }
            $this->_item->name = $this->name;

            if ($isNew) {
                UserRBACHelper::getAuthManager()->add($this->_item);
            } else {
                UserRBACHelper::getAuthManager()->update($oldName, $this->_item);
            }

            return true;
        } else {
            return false;
        }
    }
1114764
private function authenticateByToken()
    {
        $tokenType = $this->tokenType();
        $authToken = $this->tokenFactory()->create($tokenType);

        if ($authToken->metadata()->enabled() !== true) {
            return null;
        }

        $tokenData = $authToken->getTokenDataFromCookie();
        if (!$tokenData) {
            return null;
        }
        $userId = $authToken->getUserIdFromToken($tokenData['ident'], $tokenData['token']);
        if (!$userId) {
            return null;
        }

        $u = $this->userFactory()->create($this->userType());
        $u->load($userId);

        if ($u->id()) {
            $u->saveToSession();
            return $u;
        } else {
            return null;
        }
    }
313535
public function getSignup()
    {
        // Is the user logged in?
        if (Sentinel::check())
        {
            if (Sentinel::inRole('admin'))
                return Redirect::route('home');
            else
                return Redirect::route('user.home');
        }

        // Show the page
        return View('auth.register');
    }
172772
public function signup()
    {
        if ($this->validate()) {
            /**
             * @var User $user
             */
            $userClassName = \Yii::$app->user->identityClass;
            $user = new $userClassName();

            if ($this->scenario == self::SCENARION_FULLINFO) {
                $user->username = $this->username;
                $user->email = $this->email;
                $user->setPassword($this->password);
                $user->generateAuthKey();
                $user->save();

                return $user;

            } else {
                if ($this->scenario == self::SCENARION_ONLYEMAIL) {

                    $password = \Yii::$app->security->generateRandomString(6);

                    $user->generateUsername();
                    $user->setPassword($password);
                    $user->email = $this->email;
                    $user->generateAuthKey();

                    if ($user->save()) {
                        \Yii::$app->mailer->view->theme->pathMap = ArrayHelper::merge(\Yii::$app->mailer->view->theme->pathMap,
                            [
                                '@app/mail' =>
                                    [
                                        '@skeeks/cms/mail-templates'
                                    ]
                            ]);

                        \Yii::$app->mailer->compose('@app/mail/register-by-email', [
                            'user' => $user,
                            'password' => $password
                        ])
                            ->setFrom([\Yii::$app->cms->adminEmail => \Yii::$app->cms->appName . ''])
                            ->setTo($user->email)
                            ->setSubject(\Yii::t('skeeks/cms', 'Sign up at site') . \Yii::$app->cms->appName)
                            ->send();

                        return $user;
                    } else {
                        \Yii::error("User rgister by email error: {$user->username} " . Json::encode($user->getFirstErrors()),
                            'RegisterError');
                        return null;
                    }
                }
            }

        }


        return null;
    }
374397
public static function signOut()
	{
		$username = self::getCurrentUsername();

		if ( ! is_null( $username ) ) {
			$ip       = self::getClientIp();
			$ua       = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ? $_SERVER['HTTP_USER_AGENT'] : '';
			$ts       = date("U");

			self::log( 'signout' , $username , $ts , $ip , $ua );
			self::save();

			self::sessionDestroy();
		}

		return $username;
	}
989365
public function sign()
	{
		$type = Input::get('type');
		$input = Input::get('input');
		$termId = $input['term'];
		$term = Terminal::find($termId);

		$input = Type::clearInput($type, $input);
		Secure::sign($input, $type, $term->secret);

		return $input['sign'];

	}
339147
private function getAuthenticatedUser()
    {
        $auth = $this->getServiceLocator()
                     ->get( 'Zend\Authentication\AuthenticationService' );

        if ( $auth->hasIdentity() )
        {
            return $auth->getIdentity();
        }

        return null;
    }
1254599
public function signed()
    {

        if ($this->q == 1) {
            return sprintf("%+d", $this->p);
        }
        return sprintf("%+d/%d", $this->p, $this->q);

    }
550355
function signIn()
    {
        if ( (null === $identity = $this->identity) || !$identity->isFulfilled() )
            throw new \Exception('Identity not exists or not fullfilled');

        $identity = serialize($identity);
        $this->_storage()->set(self::STORAGE_IDENTITY_KEY , $identity);
        return $this;
    }
995352
public function getUserData()
    {
        if (!$this->tokenStorage->getToken()
            || !$this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')
        ) {
            return null;
        }

        $user = $this->tokenStorage->getToken()->getUser();

        if (!$user) {
            return null;
        }

        return $this->userHelper->buildUserData($user);
    }