Пример #1
0
 public static function calculate($id)
 {
     if (!empty(self::$privacy) && self::$privacy['id'] == $id) {
         return self::$privacy;
     }
     $model = new UserModel();
     $user = $model->getUser($id);
     $privacy = (int) $user['privacy'];
     $x = 14;
     $user['privacy'] = array();
     foreach ($user as $key => $value) {
         if ($key == 'privacy') {
             break;
         }
         $exp = 2 ** $x;
         if ($exp <= $privacy) {
             $user['privacy'][$key . 'Privacy'] = true;
             $privacy -= $exp;
         } else {
             $user['privacy'][$key . 'Privacy'] = false;
         }
         --$x;
     }
     self::$privacy = $user['privacy'];
     return $user['privacy'];
 }
 /**
  * Insertamos un usuario en la base de datos
  *
  * @return void
  * @group insert
  */
 public function testInsertUser()
 {
     $this->notSeeInDatabase('users', ['email' => '*****@*****.**']);
     $userModel = new UserModel();
     $traveler = new Traveler();
     $traveler->setEmail('*****@*****.**');
     $traveler->setAdmin(false);
     $traveler->setPassword('123456');
     $traveler->setName('Javier');
     $traveler->setOwner(false);
     $traveler->setPhone('654321987');
     $traveler->setSurname('Comino');
     $userModel->createUser($traveler);
     $this->seeInDatabase('users', ['email' => '*****@*****.**']);
     $traveler2 = new Traveler();
     $traveler2->setEmail('*****@*****.**');
     $traveler2->setAdmin(false);
     $traveler2->setPassword('123456');
     $traveler2->setName('Javi Missed');
     $traveler2->setOwner(false);
     $traveler2->setPhone('654321987');
     $traveler2->setSurname('Vera');
     $userModel->createUser($traveler2);
     $this->notSeeInDatabase('users', ['name' => 'Javi Missed']);
 }
Пример #3
0
 /**
  * Resets password.
  *
  * @return bool if password was reset
  */
 public function resetPassword()
 {
     if ($this->validate()) {
         $this->_user->setPassword($this->password);
         return $this->_user->save(true, ['passwordHash']);
     }
     return false;
 }
Пример #4
0
 private function getInfos($article)
 {
     $article['user'] = $this->userModel->getUser($article['user']);
     $article['category'] = $this->articleModel->getCategory($article['category']);
     $postdate = new \DateTime($article['postdate']);
     $article['postdate'] = $postdate->format('d/m/Y à H:i');
     return $article;
 }
Пример #5
0
 private function setInformations()
 {
     try {
         $model = new UserModel();
         self::$informations = $model->getUser(Authentication::getInstance()->getUserId());
     } catch (InputNotSetException $e) {
         $e->getMessage();
     }
 }
Пример #6
0
 public function testUpdateUser()
 {
     $this->model = new UserModel();
     $array = ['id' => 1, 'firstname' => 'OMG'];
     $ok = $this->model->updateUser($array);
     $this->assertEquals(true, $ok);
     $array = ['id' => 1, 'firstname' => 'Thomas'];
     $ok = $this->model->updateUser($array);
     $this->assertEquals(true, $ok);
 }
 public function update()
 {
     $this->userModel = $this->loadModel('User');
     $iduser = (int) $this->getParams()[0];
     $username = Input::get('username');
     $firstname = Input::get('firstname');
     $lastname = Input::get('lastname');
     $mail = Input::get('mail');
     $password = sha1(Input::get('password'));
     $this->userModel->updateAdminUser($iduser, ['username' => $username, 'firstname' => $firstname, 'lastname' => $lastname, 'mail' => $mail, 'password' => $password]);
 }
Пример #8
0
 /**
  * Creates a new user.
  *
  * If creation is successful, the browser will be redirected to the 'index' page.
  *
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new UserModel(['scenario' => 'createUser']);
     if ($model->load(Yii::$app->request->post())) {
         if ($model->createUser()) {
             Yii::$app->session->setFlash('success', Yii::t('user', 'User has been created.'));
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #9
0
 private function getInfos($event)
 {
     if (Authentication::getInstance()->isAuthenticated()) {
         $event['participating'] = $this->eventModel->getParticipateUser($event['id'], Authentication::getInstance()->getUserId());
     }
     $event['user'] = $this->userModel->getUser($event['user']);
     $createtime = new \DateTime($event['createtime']);
     $event['createtime'] = $createtime->format('d/m/Y à H:i');
     $eventtime = new \DateTime($event['eventtime']);
     $event['eventtime'] = $eventtime->format('d/m/Y à H:i');
     return $event;
 }
Пример #10
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new UserModel();
         $user->login = $this->login;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $user->save();
         return $user;
     }
     return null;
 }
 /**
  * @param Form $form
  */
 public function successEditUserCollectionForm(Form $form)
 {
     $albumIds = $form->values->albums;
     $albums = [];
     foreach ($albumIds as $albumId => $isSet) {
         if ($isSet) {
             $albums[] = $this->albumModel->get($albumId);
         }
     }
     $this->userModel->assignAlbums($this->user, $albums);
     $this->presenter->flashMessage('Albums have been assigend');
     $this->presenter->redirect(':Users:List');
 }
Пример #12
0
 public function signup()
 {
     // grappping the registered user information via request
     $name = Request::getParam('name');
     $email = Request::getParam('email');
     $pass = Request::getParam('pass');
     $mobile = Request::getParam('mobile');
     $tel = Request::getParam('tel');
     $address = Request::getParam('address');
     $diagnostic = Request::getParam('diagnostic');
     $description = Request::getParam('description');
     $hash = UserModel::getHash();
     $user_columns = ['name' => $name, 'email' => $email, 'pass' => Hash::make($pass), 'mobile' => $mobile, 'tel' => $tel, 'address' => $address, 'hash' => $hash, 'avatar' => ''];
     // inserting new user
     if (UserModel::insert($user_columns)) {
         // check if there is a complain then insert it
         $complain = ['user_id' => UserModel::lastId(), 'diagnostic' => $diagnostic, 'description' => $description];
         if (!empty($description) && !empty($diagnostic)) {
             ComplainModel::insert($complain);
         }
         // inserting permissions for the user as normal
         $permissions = ['user_id' => UserModel::lastId()];
         PermissionModel::insert($permissions);
         // login the user
         $u = new User($hash);
         $u->login();
         // redirect the user to profile page
         redirect(route('user.profile'));
     } else {
         Response::error(401);
     }
 }
Пример #13
0
 /**
  * Finds user by [[email]]
  *
  * @return UserModel|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = UserModel::findByEmail($this->email);
     }
     return $this->_user;
 }
Пример #14
0
 public function testCorrectResetPassword()
 {
     $user = UserModel::findOne(['email' => '*****@*****.**']);
     $this->_model = new ResetPasswordForm($user, ['password' => '123456', 'confirmPassword' => '123456']);
     expect($this->_model->resetPassword())->true();
     expect($this->_model->errors)->isEmpty();
 }
Пример #15
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = UserModel::findByLogin($this->login);
     }
     return $this->_user;
 }
Пример #16
0
 function control($next)
 {
     $user_data = Request::getALlParams();
     Validation::check($user_data, ['name' => ['required' => true, 'unicode_space' => true, 'min' => 2, 'title' => 'Name'], 'email' => ['field' => 'email', 'title' => 'E-mail'], 'pass' => ['required' => true, 'field' => 'nr_password', 'min' => 8, 'title' => 'Password'], 'newpass' => ['field' => 'nr_password', 'min' => 8, 'title' => 'New Password'], 'repass' => ['matches' => 'newpass', 'title' => 'Re-password'], 'tel' => ['field' => 'phone', 'title' => 'Telephone'], 'mobile' => ['field' => 'phone', 'title' => 'Mobile']]);
     $avatar = Request::getFile('avatar');
     $str = '';
     if (Validation::passed()) {
         // grapping the current user data
         $user = User::getData();
         // password check
         if (Hash::match(Request::getParam('pass'), $user->pass)) {
             // if the avatar is set it will be tested
             $avatarFlag = true;
             if (!empty($avatar)) {
                 $avatarFlag = $avatar->size <= 100000 && scanImageToPng($avatar->tmp_name, Url::resource("images/{$avatar->name}"));
                 if (!$avatarFlag) {
                     $str .= '<li><span class="msg-error" >Error: </span> The Avatar must be an image and less that 10 MB</li>';
                 }
             }
             //if the email changed it will be tested
             $email = Request::getParam('email');
             $emailFlag = true;
             if ($user->email != $email && UserModel::findBy(['email' => $email])) {
                 $emailFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Email already Exists choose another one</li>';
             }
             //if the telephone changed it will be tested
             $tel = Request::getParam('tel');
             $telFlag = true;
             if ($user->tel != $tel && UserModel::findBy(['tel' => $tel])) {
                 $telFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Telephone already Exists choose another one</li>';
             }
             //if the mobile changed it will be tested
             $mobile = Request::getParam('mobile');
             $mobileFlag = true;
             if ($user->mobile != $mobile && UserModel::findBy(['mobile' => $mobile])) {
                 $mobileFlag = false;
                 $str .= '<li><span class="msg-error" >Error: </span> The Mobile already Exists choose another one</li>';
             }
             // if the avatar test and the email test and the mobile test and the telephone test are passed,
             //  move to next step
             if ($avatarFlag && $emailFlag && $mobileFlag && $telFlag) {
                 return $next();
             }
         } else {
             $str .= '<li><span class="msg-error" >Error: </span> The Password doesn\'t match the current one</li>';
         }
     }
     $msgs = Validation::getAllErrorMsgs();
     if (count($msgs)) {
         foreach ($msgs as $msg) {
             $str .= '<li><span class="msg-error" >Error: </span> ' . $msg . '</li>';
         }
     }
     Session::flash('msg', $str);
     Session::flash('data', $user_data);
     goBack();
 }
Пример #17
0
 public function __construct()
 {
     parent::__construct();
     if (\Session::has('user.username')) {
         $this->limit = UserModel::where('username', \Session::get('user.username'))->first()->limit;
     }
     $this->userid = \Session::has('user.uid') ? \Session::get('user.uid') : redirect('/login');
 }
Пример #18
0
 public function dologin()
 {
     $userModel = UserModel::where('username', Input::get('username'))->first();
     //查看是否有此用户
     if (!$userModel) {
         echo "<script>alert('没有此用户!');history.go(-1);</script>";
         exit;
     }
     //验证密码正确否
     if (!Hash::check(Input::get('password'), $userModel->password)) {
         echo "<script>alert('密码错误!');history.go(-1);</script>";
         exit;
     }
     //查看2次密码输入是否一致
     if (Input::get('password') != Input::get('password2')) {
         echo "<script>alert('2次密码输入不一致!');history.go(-1);</script>";
         exit;
     }
     //验证码验证
     $rules = ['captcha' => 'required|captcha'];
     $messages = ['captcha.required' => '请输入验证码', 'captcha.captcha' => '验证码错误,请重试'];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         echo "<script>alert('验证码错误!');history.go(-1);</script>";
         exit;
     }
     //个人资料
     if (in_array($userModel->isuser, [1, 3])) {
         $personModel = PersonModel::where('uid', $userModel->id)->first();
         $persons['per_id'] = $personModel->id;
         $persons['realname'] = $personModel->realname;
         $persons['sex'] = $personModel->sex;
         $persons['idcard'] = $personModel->idcard;
         $persons['idfront'] = $personModel->idfront;
     }
     $userperson = isset($persons) ? serialize($persons) : [];
     //企业资料
     if (in_array($userModel->isuser, [2, 4])) {
         $companyModel = CompanyModel::where('uid', $userModel->id)->first();
         $companys['cid'] = $companyModel->id;
         $companys['name'] = $companyModel->name;
         $companys['area'] = $companyModel->area;
         $companys['address'] = $companyModel->address;
         $companys['yyzzid'] = $companyModel->yyzzid;
     }
     $usercompany = isset($companys) ? serialize($companys) : [];
     $serial = date('YmdHis', time()) . rand(0, 10000);
     $userInfo = ['uid' => $userModel->id, 'username' => Input::get('username'), 'email' => $userModel->email, 'userType' => $userModel->isuser, 'serial' => $serial, 'area' => $userModel->area, 'address' => $userModel->address, 'cid' => isset($companyModel) ? $companyModel->id : '', 'loginTime' => time(), 'person' => $userperson, 'company' => $usercompany];
     Session::put('user', $userInfo);
     //登陆加入用户日志表
     $ip = \App\Tools::getIp();
     $ipaddress = \App\Tools::getCityByIp($ip);
     $userlog = ['uid' => $userModel->id, 'uname' => Input::get('username'), 'genre' => 1, 'serial' => $serial, 'ip' => $ip, 'ipaddress' => $ipaddress, 'action' => $_SERVER['REQUEST_URI'], 'loginTime' => time(), 'created_at' => $userModel->created_at];
     LogModel::create($userlog);
     //最近登录更新
     UserModel::where('id', $userModel->id)->update(['lastLogin' => time()]);
     return redirect(DOMAIN . 'member');
 }
Пример #19
0
 public function __construct()
 {
     $user = UserModel::getUser('user');
     if ($user) {
         if ($user->role == 'super_admin' || $user->role == 'admin') {
             return true;
         }
     }
     die('Access denied');
 }
Пример #20
0
 public function index($from = 1, $type = 0)
 {
     if ($from == 1) {
         $prefix_url = DOMAIN . 'person';
     } elseif ($from == 2) {
         $prefix_url = DOMAIN . 'person/s/' . $from . '/' . $type;
     }
     $result = ['datas' => $this->query($from, $type), 'prefix_url' => $prefix_url, 'goodsModel' => $this->goodsModel, 'productModel' => $this->productModel, 'user' => UserModel::find($this->userid), 'from' => $from, 'type' => $type];
     return view('person.home.index', $result);
 }
Пример #21
0
 public function __construct()
 {
     parent::__construct();
     $this->userid = \Session::has('user.uid') ? \Session::get('user.uid') : redirect('/login');
     $userSpace = \App\Models\UserParamsModel::where('uid', $this->userid)->first();
     $this->user = \App\Models\UserModel::find($this->userid);
     $userlog = \App\Models\Admin\LogModel::where('uid', $this->userid)->orderBy('id', 'asc')->get();
     //注册的记录
     $this->user->spaceTopBgImg = $userSpace->getPicUrl();
     $this->user->userlog = $userlog;
 }
Пример #22
0
 /**
  * Creates a form model given a token.
  *
  * @param  string $token
  * @param  array  $config name-value pairs that will be used to initialize the object properties
  *
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException('Password reset token cannot be blank.');
     }
     $this->_user = UserModel::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
 public function init()
 {
     parent::init();
     $this->groups['registration'] = array_merge($this->groups['personalArea'], $this->groups['newRequest']);
     foreach ($this->groups[$this->scenario] as $name) {
         $this->{$name} = null;
     }
     switch ($this->scenario) {
         case 'login':
             $this->rememberMe = true;
     }
 }
Пример #24
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Пример #25
0
 public function users()
 {
     $users_all = UserModel::all();
     $users_week = LogModel::where('loginTime', '>', time() - 3600 * 24 * 7)->distinct('uid')->get();
     $users_hour = LogModel::where('loginTime', '>', time() - 3600)->distinct('uid')->get();
     //最新注册用户
     $datas = UserModel::where('isauth', '>', 0)->where('created_at', '>', time() - 3600 * 24 * 7)->orderBy('id', 'desc')->paginate($this->limit);
     if (!count($datas)) {
         $datas = UserModel::where('isauth', '>', 0)->orderBy('id', 'desc')->paginate($this->limit);
     }
     return array('datas' => $datas, 'all' => count($users_all), 'week' => count($users_week), 'hour' => count($users_hour));
 }
Пример #26
0
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = UserModel::findOne(['status' => UserModel::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         $user->generatePasswordResetToken();
         if ($user->save()) {
             return \Yii::$app->mail->compose('passwordResetToken', ['user' => $user])->setFrom(\Yii::$app->params['adminEmail'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
         }
     }
     return false;
 }
Пример #27
0
 public function registerAction()
 {
     $request = $this->getRequest();
     $data = $this->getFormFields('register');
     if ($request->isMethod('POST')) {
         $data = $request->all();
         $userModel = new UserModel($this->getDatabase());
         $user = $userModel->findByName($request->getPost('username'));
         if ($user) {
             // the username is taken
             $data['error'] = 'The username has been taken, please choose different one';
         } else {
             // the username is available, register a new user
             $user = $request->all();
             $user['id'] = $userModel->addUser($user);
             $this->getSession()->set('user', $user);
             $this->redirect('/welcome');
         }
     }
     return $this->render('register', $data);
 }
Пример #28
0
 /**
  * Incrementing app users profile visits count by user id.
  * The return value of this function is the actual visits count of that 
  * respective profile.
  * 
  * @param integer $userId
  * @return integer 
  */
 public static function incrementProfileVisits($userId)
 {
     $visits = 0;
     if (!empty($userId)) {
         $user = UserModel::find($userId);
         if (!empty($user)) {
             $visits = $user->app_user_profile_visits + 1;
             $user->app_user_profile_visits = $visits;
             $user->save();
         }
     }
     return $visits;
 }
Пример #29
0
 public static function getUser($key)
 {
     if (isset($_SESSION[$key])) {
         $value = $_SESSION[$key];
         return unserialize($value);
     } elseif (isset($_COOKIE[$key])) {
         $str = 'avtobus12troleibus23h23';
         $encrypted = $_COOKIE[$key];
         $email = FL::decrypted($encrypted, $str);
         return UserModel::getByColumn('email', $email);
     } else {
         return false;
     }
 }
 function create()
 {
     //-- only POST allowed:
     if (filter_input(INPUT_SERVER, 'REQUEST_METHOD') != "POST") {
         //-- It is supposed to be (only) POST. If not, kill the request.
         throw new \Exception("Not allowed method for this action!");
     }
     //-- get post values from request:
     $post_values = filter_input_array(INPUT_POST);
     //-- check if user params are present on request:
     if (!isset($post_values['user'])) {
         throw new \Exception("User params missing");
     }
     //-- new User instance:
     $new_register = new UserModel();
     //-- check if post values are valid:
     $is_valid_result = $new_register->isValid($post_values['user']);
     //-- is it valid?
     if ($is_valid_result === true) {
         //-- try to save:
         $save_result = $new_register->save($post_values['user']);
         if ($save_result === true) {
             //-- set a simple success message on flash var:
             $_SESSION['FLASH'] = array("success" => "Registo Conclu&iacute;do!");
             //-- redirect to index action:
             header("Location: " . REGISTER_ROUTE);
             exit;
         } else {
             //-- fail message to user with parameters:
             $this->_params = array("fail" => $save_result, "user" => $post_values['user']);
         }
     } else {
         //-- case invalid, show message to user, with parameters:
         $this->_params = array("fail" => $is_valid_result, "user" => $post_values['user']);
     }
     $this->assign("params", $this->_params);
 }