public function signup($post_data) { $user = new Users(); $user->username = $post_data['username']; $user->username_rus = $post_data['runame']; $user->pasport_code = (int) $post_data['passport_code']; $user->ref_id = $post_data['user_ref_id']; $user->password = Yii::$app->getSecurity()->generatePasswordHash($post_data['password']); $user->social_role = 'N'; $user->ip = $_SERVER['REMOTE_ADDR']; $this->photo = UploadedFile::getInstanceByName('userfile'); if ($this->photo) { $user->avatar = $this->photo->baseName . '.' . $this->photo->extension; } if ($user->save()) { if ($this->photo) { mkdir('./images/users_photo/' . $user->id . '/avatar/', 0777, true); // chmod('./images/users_photo/' . $user->id, 0777); // chmod('./images/users_photo/' . $user->id . '/avatar/', 0777); $this->photo->saveAs('images/users_photo/' . $user->id . '/avatar/' . $this->photo->baseName . '.' . $this->photo->extension); } if (Yii::$app->session->has('guest')) { $guest = Yii::$app->session->get('guest'); UsersParameters::syncFromGuestsParameters($user->id, $guest->id); UsersStats::syncFromGuestsStats($user->id, $guest->id); Yii::$app->session->remove('guest'); } Yii::$app->user->login($user, 3600 * 24 * 30); return true; } else { return false; } }
public static function add($username, $password, $org_id) { $cashier = new Users(); $cashier->social_role = self::SOCIAL_ROLE; $cashier->username = $username; $cashier->password = $password; $cashier->pasport_code = Users::getPassportCode(self::SOCIAL_ROLE); if ($cashier->save()) { $cashier_org_relation = new OrganizationsCashiers(); $cashier_org_relation->user_id = $cashier->id; $cashier_org_relation->organization_id = $org_id; return $cashier_org_relation->save(); } return false; }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = Users::findByUsernameAndPassport($this->username, $this->passport); } return $this->_user; }
public function change(array $option = []) { $user = Users::find()->where(['id' => Yii::$app->user->id])->one(); foreach ($option as $key => $item) { if (property_exists($this, $key) && $key != 'avatar') { $user->{$key} = $item; } } $this->avatar = UploadedFile::getInstance($this, 'avatar'); if ($this->avatar) { $user->avatar = "{$this->avatar->baseName}.{$this->avatar->extension}"; } if ($user->save()) { if ($this->avatar) { $folder_path = "./images/users_photo/{$user->id}/avatar/"; if (!is_dir($folder_path)) { mkdir($folder_path, 0777, true); } else { $file = $folder_path . $user->avatar; if (is_file($file)) { unlink($file); } } $this->avatar->saveAs($folder_path . $user->avatar); } } }
/** * @inheritdoc */ public function rules() { return [[['username', 'password'], 'required'], ['password', 'string', 'min' => self::MIN_PASS_LEN, 'max' => self::MAX_PASS_LEN, 'message' => '4-12 символов'], ['username', function ($username, $param) { if (Users::find()->where(['username' => $this->{$username}])->exists()) { $this->addError($username, 'Такое имя пользователя уже занято'); } }]]; }
public function change() { if ($this->validate()) { $user = Users::find()->where(['id' => Yii::$app->user->id])->one(); $user->password = Yii::$app->security->generatePasswordHash($this->new_pass); return $user->save(); } return false; }
public function actionIndex() { $form_model = new Profile(); $post = \Yii::$app->request->post('Profile'); if ($post) { $form_model->change($post); } $user = Users::find()->where(['id' => Yii::$app->user->id])->asArray()->one(); foreach ($user as $key => $item) { if (property_exists($form_model, $key) && $key != 'avatar') { if (strlen($item) < 1) { $user[$key] = "-"; } $form_model->{$key} = $item; } } $avatar_path = "./images/users_photo/" . Yii::$app->user->id . "/avatar/"; if (!is_file($avatar_path . $user['avatar'])) { $user['avatar'] = "./images/faces/nomen.png"; } else { $user['avatar'] = $avatar_path . $user['avatar']; } return $this->render('index', ['form_model' => $form_model, 'user' => $user]); }
public function actionSearchUserRef() { $search_string = \Yii::$app->getRequest()->post('search'); if (\Yii::$app->getRequest()->isAjax && $search_string) { return Users::getUsersByNames($search_string); } }
public static function getPassportCode($social_role) { $passport_code = Users::find()->select("MAX(`pasport_code`)+1 as pcode")->where(['social_role' => $social_role])->scalar(); if (!$passport_code) { return 1; } return $passport_code; }
public static function getByUserId($user_id) { $sql = 'SELECT o.id, o.nice_name ' . ' FROM ' . self::tableName() . ' o ' . ' JOIN ' . UsersOrganizations::tableName() . ' uo ' . ' ON o.id = uo.organization_id ' . ' JOIN ' . Users::tableName() . ' u ' . ' ON u.id = uo.user_id ' . ' WHERE u.id = :user_id' . ' ORDER BY o.nice_name '; return self::findBySql($sql, [':user_id' => $user_id])->asArray()->all(); }