本文整理汇总了PHP中app\models\Users类的典型用法代码示例。如果您正苦于以下问题:PHP Users类的具体用法?PHP Users怎么用?PHP Users使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Users类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new Staff model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
if (Yii::$app->user->can('admin')) {
$model = new Staff();
if (Yii::$app->request->isAjax && $model->load($_POST)) {
Yii::$app->response->format = 'json';
return \yii\widgets\ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
$user = new Users();
$user->usertype = 'Staff';
$user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2));
$user->email = $model->correo;
$model->save();
$user->id_orig = $model->id;
$user->username = $model->nombre . " " . $model->apellido1;
$user->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', ['model' => $model]);
}
} else {
throw new ForbiddenHttpException();
}
}
示例2: actionReg
public function actionReg()
{
$model = new RegForm();
$error = null;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$user = new Users();
$user->login = Html::encode($model->login);
$user->password = md5($model->password);
$user->name = Html::encode($model->name);
$user->email = Html::encode($model->email);
$user->phone = Html::encode($model->phone);
if (UploadedFile::getInstance($model, 'photo')) {
$model->photo = UploadedFile::getInstance($model, 'photo');
$model->photo->saveAs('img/photo/' . $model->photo->baseName . '.' . $model->photo->extension);
$photo = 'img/photo/' . $model->photo->baseName . '.' . $model->photo->extension;
$user->photo = $photo;
}
$uc = new UserClass();
if ($uc->isUniqueLogin($user->login)) {
$user->save();
return $this->render('regsuccess');
} else {
$error = 'Такой логин уже существует';
}
}
return $this->render('reg', ['model' => $model, 'error' => $error]);
}
示例3: indexAction
/**
* Action to register a new user
*/
public function indexAction()
{
$form = new RegisterForm();
if ($this->request->isPost()) {
$name = $this->request->getPost('name', array('string', 'striptags'));
$username = $this->request->getPost('username', 'alphanum');
$email = $this->request->getPost('email', 'email');
$password = $this->request->getPost('password');
$repeatPassword = $this->request->getPost('repeatPassword');
if ($password != $repeatPassword) {
$this->flash->error('Passwords are different');
return false;
}
$user = new Users();
$user->username = $username;
$user->password = sha1($password);
$user->name = $name;
$user->email = $email;
$user->created_at = new \Phalcon\Db\RawValue('now()');
$user->active = 'Y';
if ($user->save() == false) {
foreach ($user->getMessages() as $message) {
$this->flash->error((string) $message);
}
} else {
$this->tag->setDefault('email', '');
$this->tag->setDefault('password', '');
$this->flash->success('Thanks for sign-up, please log-in to start generating invoices');
return $this->forward('session/index');
}
}
$this->view->form = $form;
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
if ($request->userID) {
$user = Users::where("uID", $request->userID)->first();
if ($request->password) {
$user->uPassword = md5($request->password);
}
} else {
$user = new Users();
$user->uPassword = md5($request->password);
$user->uRegisteredDate = date('Y-m-d');
$user->uIsActive = 1;
$user->uRole = 1;
$user->uUsername = $request->username;
$user->uEmail = $request->email;
}
$user->uBirthday = date('Y-m-d', strtotime($request->birthday));
$user->uAddress = $request->address;
$user->uPhone = $request->phone;
$file = Input::file('image');
// $file->getRealPath()
if (!is_null($file)) {
$destinationPath = public_path() . '/assets/images/avatar/';
$fileName = explode(".", $file->getClientOriginalName())[0];
$fileName = $fileName . rand(1, 9999) . "." . $file->getClientOriginalExtension();
Input::file('image')->move($destinationPath, $fileName);
Image::make($destinationPath . $fileName)->resize(400, 400)->save($destinationPath . '400x400/' . $fileName);
$user->uAvatar = $fileName;
}
$user->save();
return Redirect::action('admin\\user@index');
}
示例5: loginAction
public function loginAction()
{
if (!is_null($this->session->getCurrentUser())) {
$this->redirect('/');
}
if (is_null($this->request->getPost('user')) || is_null($this->request->getPost('password'))) {
throw new LoginException('Неверные данные формы авторизации.');
}
$user = addslashes(trim(strip_tags($this->request->getPost('user'))));
$password = addslashes(trim(strip_tags($this->request->getPost('password'))));
$usersModel = new Users();
try {
$currentUser = $usersModel->getUsersDataByLogPass($user, $password);
} catch (\Exception $e) {
throw new LoginException($e->getMessage());
}
if ($currentUser['roles_id'] == self::BANNED) {
throw new LoginException('Доступ временно запрещен. Обратитесь к администратору.');
}
unset($currentUser['password']);
$userObj = new User();
$userObj->fillData($currentUser);
$this->session->setCurrentUser($userObj);
echo json_encode(array('location' => '/'));
exit;
}
示例6: userInfo
public function userInfo($userInfo)
{
print_r($userInfo);
$user = new Users();
$user->email = $userInfo['email'];
$user->name = $userInfo['name'];
$user->save();
}
示例7: saveAction
public function saveAction()
{
if (!$this->isXmlHttpRequest()) {
throw new \Exception('Неверный тип запроса!');
}
$usersModel = new Users();
$data = $this->request->getPost();
if (!isset($data['id']) || !isset($data['roles_id']) || !isset($data['user']) || !isset($data['password'])) {
throw new \Exception('Неверный тип запроса!');
}
if ($data['action'] == 'add' && (!isset($data['lastname']) || !isset($data['firstname']) || !isset($data['secondname']) || !isset($data['org_name']))) {
throw new \Exception('Неверный тип запроса!');
}
$data['id'] = (int) $data['id'];
if (!$data['id'] && $data['action'] != 'add') {
throw new \Exception('Неверный идентификатор пользователя!');
}
$data['roles_id'] = (int) $data['roles_id'];
if ($data['roles_id'] == 0) {
throw new \Exception('Не выбраны права пользователя!');
}
$data['user'] = trim($data['user']);
if ($data['user'] == '') {
throw new \Exception('Не заполнено обязательное поле Email!');
}
$data['password'] = trim($data['password']);
if ($data['password'] == '' && $data['action'] != 'add') {
unset($data['password']);
}
if (isset($data['password']) && mb_strlen($data['password']) < 6) {
throw new \Exception('Пароль должен быть больше 6 символов!');
}
if ($data['action'] == 'add') {
$data['lastname'] = trim($data['lastname']);
if ($data['lastname'] == '') {
throw new \Exception('Не заполнено обязательное поле Фамилия!');
}
$data['firstname'] = trim($data['firstname']);
if ($data['firstname'] == '') {
throw new \Exception('Не заполнено обязательное поле Имя!');
}
$data['secondname'] = trim($data['secondname']);
if ($data['secondname'] == '') {
throw new \Exception('Не заполнено обязательное поле Отчество!');
}
$data['org_name'] = trim($data['org_name']);
if ($data['org_name'] == '') {
throw new \Exception('Не заполнено обязательное поле Организация!');
}
}
unset($data['action']);
$data['id'] = $usersModel->save($data);
$usersModel->setWhere(array('id' => $data['id']));
$uData = $usersModel->select();
$this->view->data = $uData[0];
$rolesModel = new Roles();
$this->view->roles = $rolesModel->select();
}
示例8: setUp
protected function setUp()
{
$_SERVER['REQUEST_URI'] = 'index.php';
parent::setUp();
$this->controllerSite = \Yii::$app->createControllerByID('site');
$user = new Users();
$user->username = $user->password = 'root';
$user->save();
}
示例9: reg
public function reg()
{
$user = new Users();
$user->username = $this->username;
$user->setPassword($this->password);
$user->generateAuthKey();
$user->save();
return $user;
}
示例10: actionRegister
public function actionRegister()
{
$model = new Users();
$model->load(Yii::$app->request->post());
if ($model->validate()) {
$model->save();
return $this->render('confirm', ['model' => $model]);
}
return $this->render('register', ['model' => $model]);
}
示例11: actionIndex
public function actionIndex()
{
$model = new app\models\Users();
if ($model->load(Yii::$app->request->post())) {
if ($model->validate()) {
// form inputs are valid, do something here
return;
}
}
return $this->render('form1', ['model' => $model]);
}
示例12: actionRegister
public function actionRegister()
{
$model = new Users();
$result = ['model' => $model];
if (\Yii::$app->request->isPost) {
$post = \Yii::$app->request->post();
if ($model->load($post) && $model->validate()) {
echo '注册成功';
}
}
return $this->render('register', $result);
}
示例13: test_validates
public function test_validates()
{
$user = new Users();
$user->username = 'yurii';
$user->password = 'pass';
$user->access_token = 'token';
$user->save();
/* @var $user_db Users */
$user_db = Users::getUserByUsername('yurii');
$this->assertTrue($user_db->validatePassword('pass'));
$this->assertTrue($user_db->validateAuthKey($user->auth_key));
}
示例14: beforeSave
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$adminUserModel = new Users();
$adminUserModel->setPassword($this->password_hash);
//print_r($adminUserModel->password_hash);exit();
$this->password_hash = $adminUserModel->password_hash;
return true;
} else {
return false;
}
}
示例15: register
public function register()
{
if (!$this->validate()) {
return false;
}
$user = new Users();
$user->login = $this->login;
$user->password_hash = Yii::$app->security->generatePasswordHash($this->password);
$user->save();
Yii::$app->user->login(User::findByUsername($this->login), 3600 * 24 * 30);
return true;
}