Inheritance: extends yii\db\ActiveRecord
示例#1
1
 /**
  * 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();
     }
 }
 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]);
 }
 /**
  * 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
0
 /**
  * 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
0
 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
0
 public function userInfo($userInfo)
 {
     print_r($userInfo);
     $user = new Users();
     $user->email = $userInfo['email'];
     $user->name = $userInfo['name'];
     $user->save();
 }
示例#7
0
 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();
 }
 protected function setUp()
 {
     $_SERVER['REQUEST_URI'] = 'index.php';
     parent::setUp();
     $this->controllerSite = \Yii::$app->createControllerByID('site');
     $user = new Users();
     $user->username = $user->password = '******';
     $user->save();
 }
示例#9
0
 public function reg()
 {
     $user = new Users();
     $user->username = $this->username;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     $user->save();
     return $user;
 }
 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
0
 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
0
 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
0
 public function test_validates()
 {
     $user = new Users();
     $user->username = '******';
     $user->password = '******';
     $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
0
 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;
     }
 }
 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;
 }
 /**
  * Store a newly created resource in storage.
  * POST
  * @return Response
  */
 public function store()
 {
     $Users = new Users();
     $Users->first_name = 'Michael';
     $Users->last_name = 'Pierre';
     $Users->age = '31';
     $Users->city = 'Orlando';
     $Users->state = 'Florida';
     $Users->country = 'USA';
     $Users->about = 'Cool Dude';
     $Users->save();
     return Users::where('uid', $Users->id)->get();
 }
示例#17
0
 public function reg()
 {
     $user = new Users();
     $user->family = $this->family;
     $user->name = $this->name;
     $user->father = $this->father;
     $user->login = $this->login;
     $user->setPassword($this->password);
     $user->email = $this->email;
     $user->phone = $this->phone;
     //$user->generateAuthKey();
     return $user->save() ? $user : null;
 }
示例#18
0
 public function actionAuthenticate()
 {
     $request = Yii::$app->request;
     $username = $request->post('username');
     $user = Users::findByUsername($username);
     // Just create the user if not found
     if (!$user) {
         $user = new Users();
         $user->username = $username;
         $user->save();
     }
     echo json_encode(['auth' => $user->getId() ? true : false, 'id' => $user->id, 'username' => $user->username]);
 }
示例#19
0
 public function signup()
 {
     if ($this->validate()) {
         $users = new Users();
         $users->name = $this->name;
         $users->email = $this->email;
         $users->status = $this->status;
         $users->setPassword($this->password);
         $users->generateAuthKey();
         return $users->save() ? $users : null;
     }
     return null;
 }
示例#20
0
 public function actionTest()
 {
     $users = [];
     $musers = [];
     for ($i = 0; $i < 5; $i++) {
         $no = str_pad($i + 1, 5, 0, STR_PAD_LEFT);
         $u = ['user_name' => 'user' . $no, 'mobile' => 'mobile' . $no, 'idcard' => 'idcard' . $no, 'create_time' => time()];
         $user = new Users();
         $user->attributes = $u;
         $user->save();
         $users[] = $user;
     }
     //$user = Users::loadMultiple($musers,$users);
     var_dump($users);
 }
 public function execute($user, $item, $params)
 {
     $user_role = Users::findOne($user)->authAssignments->item_name;
     if (isset($params['news'])) {
         $news_status = $params['news']->status;
         $news_category = $params['news']->category_id;
         $relCat = !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news_category]));
         if ($user_role == 'moderator' && $relCat && isset($params['action']) && $params['action'] == 'view') {
             return true;
         }
         if ($news_status == News::MODER_NEWS) {
             if ($user_role == 'moderator') {
                 return $relCat;
             }
         }
         if ($news_status == News::SMODER_NEWS) {
             if ($user_role == 'super_moderator') {
                 return true;
             }
         }
     } elseif (isset($params['question'])) {
         if ($user_role == 'moderator') {
             $news = News::findOne($params['question']->news_id);
             if (!is_null($news)) {
                 if ($news->status == News::MODER_NEWS && !is_null(RelationCategories::findOne(['user_id' => $user, 'category_id' => $news->category_id]))) {
                     return true;
                 }
             }
         }
     }
     return false;
 }
示例#22
0
 public function sendMailToAuthor($news, $subject)
 {
     $user = \app\models\Users::findOne($news->user_id);
     $body = sprintf('%s <br />
         Ссылка на новость - %s', $subject['author'], $this->urlToNews($news->id));
     $this->sendMail($user->email, $subject['author'], $body);
 }
示例#23
0
 public function index()
 {
     view()->share('menu_item_active', 'index');
     Title::prepend('Dashboard');
     $data = ['title' => Title::renderr(' : ', true), 'posts_total' => Posts::count(), 'posts_active' => Posts::where('status', 'active')->count(), 'posts_draft' => Posts::where('status', 'draft')->count(), 'posts_moderation' => Posts::where('status', 'moderation')->count(), 'users_total' => Users::count(), 'users_active' => Users::where('active', '1')->count(), 'users_inactive' => Users::where('active', '0')->count(), 'latest_posts' => Posts::active()->orderBy('published_at', 'desc')->limit(5)->get(), 'popular_posts' => Posts::active()->orderBy('views', 'desc')->limit(5)->get()];
     return view('root.dashboard.index', $data);
 }
 /**
  * Edit the active user profile
  *
  */
 public function profileAction()
 {
     //Get session info
     $auth = $this->session->get('auth');
     //Query the active user
     $user = Users::findFirst($auth['id']);
     if ($user == false) {
         return $this->forward('index/index');
     }
     if (!$this->request->isPost()) {
         $this->tag->setDefault('name', $user->name);
         $this->tag->setDefault('email', $user->email);
     } else {
         $name = $this->request->getPost('name', array('string', 'striptags'));
         $email = $this->request->getPost('email', 'email');
         $user->name = $name;
         $user->email = $email;
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->flash->success('Your profile information was updated successfully');
         }
     }
 }
示例#25
0
文件: User.php 项目: AtaBashir/ams
 /**
  * Finds user by username
  *
  * @param  string      $username
  * @return static|null
  */
 public static function findByUsername($username)
 {
     $dbUser = DbUser::find()->where(["usr_id" => $username, "usr_active" => 1])->one();
     if (!count($dbUser)) {
         return null;
     }
     // 	self::$users[100]=['id'=>100,'usr_id' => $dbUser->usr_id, 'usr_name' => $dbUser->usr_name];
     //     	self::$users= [
     //          '100' => [
     //              'id' => '100',
     //              'usr_id' => 'Admin',
     //              'usr_pass' => 'Admin',
     //              'authKey' => 'test100key',
     //              'accessToken' => '100-token',
     //          ]];
     // 	die(var_dump(self::$users));
     //     	foreach (self::$users as $user) {
     //     		if (strcasecmp($user['usr_id'], $username) === 0) {
     //     			return new static($user);
     //     		}
     //     	}
     //     	return null;
     return new static($dbUser);
     //     	         foreach (self::$users as $user) {
     //     		             if (strcasecmp($user['usr_id'], $username) === 0) {
     //     		                 return new static($user);
     //     		             }
     //     	         }
 }
示例#26
0
 /**
  * Finds user by [[username]]
  *
  * @return Users|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = Users::findByEmail($this->email);
     }
     return $this->_user;
 }
示例#27
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = Users::findByUsername($this->username);
     }
     return $this->_user;
 }
示例#28
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = Users::findByLogin($this->login);
     }
     return $this->_user;
 }
 public function __construct()
 {
     $this->model = Users::getInstance();
     if (!$this->isAdmin()) {
         return Redirect::to("logout");
     }
 }
示例#30
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = Users::find()->where(['UserName' => $this->username, 'Password' => md5($this->password)])->one();
     }
     return $this->_user;
 }