Signs user up.

@return User|null the saved model or null if saving fails
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;
    }
1019044
public function actionSignup()
    {
        $request = \Yii::$app->request;
        if ($request->getIsOptions()) {
            return $this->ResponseOptions($this->verbs()['signup']);
        }
        try{
            $model = new SignupForm();
            $model->setAttributes(Yii::$app->request->post());
            $user = $model->signup();
            if ($user !=null) {
                return ["success"=>true,"message"=>"创建成功！"];
            }else{
                return ["success"=>false,"message"=>"参数错误！"];
            }
        }catch(Exception $e){
            throw new Exception($e);
        }



    }
1215264
public function createUserAction()
    {
        if(!$this->identity()) {
          return $this->redirect()->toRoute($this->getOptions()->getLoginRedirectRoute());
        }
      
        try {
            $user = new User;
            
            $form = $this->getUserFormHelper()->createUserForm($user, 'CreateUser');
            $request = $this->getRequest();
            if ($request->isPost()) {
                $form->setValidationGroup('username', 'email', 'firstName', 'lastName', 'password', 'passwordVerify', 'language', 'state', 'role', 'question', 'answer', 'csrf');
                $form->setData($request->getPost());
                if ($form->isValid()) {
                    $entityManager = $this->getEntityManager();
                    $user->setEmailConfirmed(false);
                    $user->setRegistrationDate(new \DateTime());
                    $user->setRegistrationToken(md5(uniqid(mt_rand(), true)));
                    $user->setPassword(UserCredentialsService::encryptPassword($user->getPassword()));
                    $entityManager->persist($user);
                    $entityManager->flush();
                    $this->flashMessenger()->addSuccessMessage($this->getTranslatorHelper()->translate('User created Successfully'));
                    return $this->redirect()->toRoute('user-admin');                                        
                }
            }        
        }
        catch (\Exception $e) {
            return $this->getServiceLocator()->get('csnuser_error_view')->createErrorView(
                $this->getTranslatorHelper()->translate('Something went wrong during user creation! Please, try again later.'),
                $e,
                $this->getOptions()->getDisplayExceptions(),
                false
            );
        }
        
        $viewModel = new ViewModel(array('form' => $form));
        $viewModel->setTemplate('csn-user/admin/new-user-form');
        return $viewModel;
    }
800223
public function userId()
	{
		if (isset($this->user_id)) {
			return $this->user_id ? $this->user_id : null;
		}
		
		$this->check();
		$this->user_id = false;
		
		if ('user' == $this->type) {
			if ($user_id = Authorizer::getResourceOwnerId()) {
				return $this->user_id = $user_id;
			}
		}
		
		return null;
	}
786101
public function create()
    {
        $transaction = $this->getDb()->beginTransaction();

        try {
            $event = $this->getCreateUserEvent($this);
            $this->trigger(self::BEFORE_CREATE, $event);

            $this->setPassword($this->plainPassword);
            $this->generateAuthKey();

            if (!$this->save()) {
                $transaction->rollBack();

                return null;
            }

            $this->trigger(self::AFTER_CREATE, $event);

            $transaction->commit();

            return $this;
        } catch (\Exception $e) {
            $transaction->rollBack();
            Yii::warning($e->getMessage());
            throw $e;
        }
    }
549524
public function loginSuccess()
    {
        $this->userID = (int) $this->kontakt->getMyKey();
        $this->setUserLogin($this->kontakt->getDataValue($this->loginColumn));
        $this->logged = true;
        $this->addStatusMessage(sprintf(_('Sign in %s all ok'), $this->userLogin),
            'success');

        return true;
    }
223520
public function save()
    {

        if (!empty($this->ltiResultSourcedId) && !is_null($this->resourceLinkId)) {
            $ok = $this->getDataConnector()->saveUser($this);
        } else {
            $ok = true;
        }

        return $ok;

    }
1336752
public function signupAction()
    {
        $form = new SignUpForm();

        if ($this->request->isPost()) {

            if ($form->isValid($this->request->getPost()) != false) {

                $user = new Users([
                    'name' => $this->request->getPost('name', 'striptags'),
                    'email' => $this->request->getPost('email'),
                    'password' => $this->security->hash($this->request->getPost('password')),
                    'profilesId' => 2
                ]);

                if ($user->save()) {
//                    return $this->dispatcher->forward([
//                        'namespace' => 'Modules\Frontend\Controllers',
//                        'controller' => 'index',
//                        'action' => 'index'
//                    ]);
                    return $this->response->redirect('index');
                }

                $this->flash->error($user->getMessages());
            }
        }

        $this->view->form = $form;
    }
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;
        }
    }
796348
public function user()
    {
        if (!$user = Auth::getUser()) {
            return null;
        }

        if (!Auth::isImpersonator()) {
            $user->touchLastSeen();
        }

        return $user;
    }
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'];

	}
1312778
private function authenticateBySession()
    {
        $u = $this->userFactory()->create($this->userType());
        // Call static method on user
        $u = call_user_func([get_class($u), 'getAuthenticated'], $this->userFactory());

        if ($u && $u->id()) {
            $u->saveToSession();

            return $u;
        } else {
            return null;
        }
    }
444694
public function setPasswordAction()
    {
        $userId = $this->params()->fromRoute('userId', null);
        $token = $this->params()->fromRoute('token', null);

        if ($userId === null || $token === null) {
            return $this->notFoundAction();
        }

        $user = $this->getUserMapper()->findById($userId);

        if (!$user) {
            return $this->notFoundAction();
        }

        $record = $this->getUserRegistrationMapper()->findByUser($user);

        if (!$record ||  !$this->userRegistrationService->isTokenValid($user, $token, $record)) {
            // Invalid Token, Lets surprise the attacker
            return $this->notFoundAction();
        }

        if ($record->isResponded()) {
            // old link, password is already set by the user
            return $this->redirectToPostVerificationRoute();
        }

        $form = $this->getServiceLocator()->get('HtUserRegistration\SetPasswordForm');

        if ($this->getRequest()->isPost()) {
            $form->setData($this->getRequest()->getPost());
            if ($form->isValid()) {
                $this->userRegistrationService->setPassword($form->getData(), $record);

                return $this->redirectToPostVerificationRoute();
            }
        }

        return array(
            'user' => $user,
            'form' => $form
        );
    }
281477
public function getLoggedUser()
    {
        $credentials = $this->storage->getLoggedUser();

        return is_array($credentials) ? new User($credentials) : null;
    }
891404
public function getUserValue()
    {
        if (null == $this->is_valid) {
            $this->validate();
        }
        if (null !== $this->user_value && $this->is_valid) {
            if ('' === $this->user_value && true === $this->null_on_empty) {
                return null;
            }
            return $this->user_value;
        } else {
            return '';
        }
    }
1356513
protected function validateRoleUser()
    {
        $field = 'role_id';
        $value = $this->getSubmitted($field);

        if (empty($value)) {
            return null;
        }

        $label = $this->translation->text('Role');

        if (!is_numeric($value)) {
            $this->setErrorNumeric($field, $label);
            return false;
        }

        $role = $this->role->get($value);

        if (empty($role)) {
            $this->setErrorUnavailable($field, $label);
            return false;
        }

        return true;
    }
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;
	}