protected function initFromUser(User $user) { $this->_activeRecord = $user; $this->id = $user->getPrimaryKey(); $this->username = $user->username; $this->email = $user->email; $this->firstName = $user->firstname; $this->lastName = $user->lastname; }
/** * This action renders new user form on GET request and creates new user * on POST request, redirecting to `user/dashboard` page after. * * @return void * @since 0.1.0 */ public function actionNew() { $user = new \User(); if ($data = \Yii::app()->getRequest()->getPost('User')) { if ($user->setAndSave($data)) { $id = $user->getPrimaryKey(); \Yii::app()->user->sendSuccessMessage('user.creation.success', array('{user}' => $user->username)); $this->redirect(array('user/dashboard', 'created' => $id)); } else { \Yii::app()->user->sendErrorMessage('user.creation.fail'); } } $this->render('new', array('user' => $user)); }
public function register($fullname) { $user = new User(); $user->full_name = $fullname; $user->email = $this->username; $user->password = crypt($this->password); if ($user->save(false)) { $this->_id = $user->getPrimaryKey(); $this->authenticated = true; $this->setState('fullname', $user->full_name); O::app()->user->login($this); return true; } return false; }
public function register($params = array()) { extract($params); if (isset($nickname) && isset($password) && isset($mobile)) { $cache = Yii::app()->cache; $save_code = strtolower($cache->hget($mobile, 'register')); if (isset($code) && $save_code == strtolower($code)) { //查询手机是否注册过 $user = User::model()->exists(array('condition' => 'mobile=:mobile', 'params' => array(':mobile' => isset($mobile) ? $mobile : 0))); if (!$user) { Yii::import("application.extensions.Emchat.*"); $h = new Easemob(); if (isset($mobile) && $mobile) { $ur_name = 'ur_' . $mobile; $pwd = isset($password) ? $password : '******'; $res = $h->createUser($ur_name, $pwd); } $result = array('nickname' => $nickname, 'sex' => isset($sex) ? $sex : 0, 'mobile' => isset($mobile) ? $mobile : 0, 'image' => isset($image) ? $image : '', 'password' => md5($mobile . md5($password))); if ($uuid = $res['entities'][0]['uuid']) { $result['uuid'] = $uuid; } $model = new User(); $model->attributes = $result; if ($model->validate() && $model->save()) { $id = $model->getPrimaryKey(); $res = array('id' => $id, 'nickname' => $nickname, 'uuid' => $uuid); $ret = $this->notice('OK', 0, '成功', $res); } else { $ret = $this->notice('ERR', 307, '', $model->getErrors()); } } else { $ret = $this->notice('ERR', 306, '该号码已经注册过了', []); } } else { $ret = $this->notice('ERR', 305, '验证码错误', ['code' => $code, 'save_code' => $save_code]); } } else { $ret = $this->notice('ERR', 307, '', []); } $result = array('password' => $params['password']); $ret = $this->notice('ERR', 307, '', $result); return $ret; }
/** * Logs in the user using the given name and password in the model. * @return boolean whether login is successful */ public function register() { $user = new User(); $userInfo = new UserInfo(); $user->email = $this->email; $user->plainPassword = $this->password; if ($user->save()) { $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->name = $this->name; $userInfo->bio = $this->bio; // $userInfo->status="created"; $userInfo->addTime = time(); $userInfo->status = "created"; if ($userInfo->save()) { /** * added by lsy 20130819 * assign roles after registration HERE */ // $authorizer = Yii::app()->getModule("rights")->getAuthorizer(); // $authorizer->authManager->assign('Authenticated', $userInfo->id); /** * added by lsy 20130819 */ //注册成功后自动登录 //$identity=new UserIdentity($this->email,$this->password); //$identity->authenticate(); //Yii::app()->user->login($identity,0); // Yii::import("ext.sendcloud.ESendCloud"); // $sendCloud = new ESendCloud(); return true; } else { $user->delete(); } } return false; }
protected function connectSamebookUser($samebookUser) { $user = User::model()->findByAttributes(array('email' => $samebookUser['email'])); if (!$user) { $user = new User(); $user->email = $samebookUser['email']; $user->password = $samebookUser['pwd']; $user->salt = $samebookUser['salt']; if ($user->save()) { $userInfo = new UserInfo(); $userInfo->name = $samebookUser['username']; $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->introduction = $samebookUser['bio']; $userInfo->addTime = time(); $userInfo->status = 'ok'; $userInfo->save(); } } $userInfo = UserInfo::model()->findByAttributes(array('email' => $samebookUser['email'])); //列入oauth表 if (empty($userInfo->oauth)) { $oauth = new Oauth(); $oauth->userId = $user->id; $oauth->save(); } $userInfo = UserInfo::model()->findByAttributes(array('email' => $samebookUser['email'])); //在oauth表中加sbid if (!$userInfo->oauth->sbid) { $userInfo->oauth->sbid = $samebookUser['userId']; $userInfo->oauth->save(); $userInfo = User::model()->findByAttributes(array('email' => $samebookUser['email'])); } }
public function actionInit() { $model = new InstallInfoForm(); $mailer = new MailerForm(); if (isset($_POST['InstallInfoForm']) && isset($_POST['MailerForm'])) { $model->attributes = $_POST['InstallInfoForm']; $siteForm = new SiteForm(); $siteForm->name = $model->name; $siteForm->subTitle = $model->subTitle; $siteForm->saveSetting(); $user = new User(); $user->email = $model->adminEmail; $user->setPlainPassword($model->adminPassword); $user->save(); $userInfo = new UserInfo(); $userInfo->name = $model->adminName; $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->bio = $model->adminBio; $userInfo->isAdmin = 1; // $userInfo->roles = "superAdmin,admin,teacher"; $userInfo->status = "ok"; $userInfo->addTime = time(); $userInfo->introduction = "admin"; $mailer->attributes = $_POST['MailerForm']; if ($userInfo->save() && $mailer->saveSetting()) { $auth = Yii::app()->authManager; $auth->createRole('admin'); $auth->createRole('teacher'); $userInfo->roles = array('admin', 'teacher'); $this->setNav(); $this->setCarousel(); Yii::app()->user->setFlash('success', '系统初始化成功!'); $this->redirect(array('finish')); } } $this->render('init', array('model' => $model, 'mailer' => $mailer)); }
/** *添加一个用户 */ public function addUser($email, $password, $info = array()) { $user = new User(); $user->plainPassword = $password; $user->email = $email; //用户名不可缺少 if ($user->save()) { $userInfo = new UserInfo(); $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $attributes = $userInfo->getAttributes(); foreach ($info as $k => $v) { if (in_array($k, $attributes)) { $userInfo->{$k} = $v; } } $userInfo->addTime = time(); if ($userInfo->save()) { return true; } else { $user->delete(); } } return false; }
protected function regUser($access_token, $basic_account = array()) { $newUser = array('sns_uid' => $basic_account["idstr"], 'username' => $basic_account["screen_name"], 'screen_name' => $basic_account["screen_name"], 'avatar' => $basic_account["avatar_large"], 'location' => $basic_account["location"], 'gender' => $basic_account["gender"], 'access_token' => $access_token, 'reg_datetime' => time()); $mUser = new User(); foreach ($newUser as $property => $value) { $mUser->{$property} = $value; } if ($mUser->insert()) { $newUser["uid"] = $mUser->getPrimaryKey(); return $newUser; } return FALSE; }