public function login() { $proffstore = new ProffstoreCURL(); $proffstore->auth($this->password, $this->email); if ($proffstore->accesToken) { $user = \app\models\User::findOne(['email' => $this->email]); if ($user) { $user->setAttribute('tocken', $proffstore->accesToken); $user->update(false); } else { $user = new \app\models\User(); $user->setAttributes(['email' => $this->email, 'pass' => $this->password, 'tocken' => $proffstore->accesToken]); $user->setAttribute('tocken', $proffstore->accesToken); $user->save(false); } \Yii::$app->user->login($user, 3600 * 24 * 3); return $proffstore->accesToken; } else { return null; } }
/** * Page that is used for new users to register on this website. There is also a similar page on admin module called * admin/users/create where admins can create a new user. When an admin create an user then the password is generated * automatically and sent to user email address. So not even the admin can see it, just the new user. */ public function actionRegister() { if (WebApp::get()->user()->isConnected()) { // can't register if is already connected WebApp::get()->request()->goToPage('home'); } $user = new \app\models\User(); $user->setAction('register'); if (isset($_POST['register']) && $user->setAttributes($_POST['User'])->validate()) { if ($user->register()) { Messages::get()->success('Account created!'); WebApp::get()->request()->goToPage('home'); } } $this->assign('user', $user); }