/**
  * This action authenticate and logs a user into the application
  */
 public function startAction()
 {
     if ($this->request->isPost()) {
         // Get the data from the user
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $tokenKey = $this->request->getPost("token_key");
         $token = $this->request->getPost("token");
         if ($this->security->checkToken($tokenKey, $token)) {
             // Find the user in the database
             $first_user = Users::findFirst(array("(email = :email: OR username = :email:) AND status = '1'", 'bind' => array('email' => $email)));
             // validation password
             if ($first_user) {
                 $user = $this->security->checkHash($password, $first_user->password);
             }
             if ($user != false) {
                 $this->_registerSession($first_user);
                 $this->flash->success('Welcome ' . $first_user->name);
                 // Forward to the 'invoices' controller if the user is valid
                 return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
             }
         }
         $this->flash->error('Wrong email/password');
     }
     // Forward to the login form again
     return $this->dispatcher->forward(array('controller' => 'login', 'action' => 'index'));
 }
Example #2
0
 /**
  * Edit the active user profile
  *
  */
 public function profileAction()
 {
     //Get session info
     $auth = Session::get('auth');
     //Query the active user
     $user = Users::findFirst($auth['id']);
     if ($user == false) {
         $this->_forward('index/index');
     }
     if (!$this->request->isPost()) {
         Tag::setDefault('name', $user->name);
         Tag::setDefault('email', $user->email);
     } else {
         $name = $this->request->getPost('name', 'string');
         $email = $this->request->getPost('email', 'email');
         $name = strip_tags($name);
         $user->name = $name;
         $user->email = $email;
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 Flash::error((string) $message, 'alert alert-error');
             }
         } else {
             Flash::success('Your profile information was updated successfully', 'alert alert-success');
         }
     }
 }
Example #3
0
 public function user()
 {
     if (null == $this->user) {
         $this->user = Users::findFirst($this->user_id);
     }
     return $this->user;
 }
 public function profileAction()
 {
     $auth = $this->session->get('auth');
     $user = Users::findFirst($auth['id']);
     if ($user == false) {
         $this->_forward('index/index');
     }
     $request = $this->request;
     if (!$request->isPost()) {
         Tag::setDefault('name', $user->name);
         Tag::setDefault('email', $user->email);
     } else {
         $name = $request->getPost('name', 'string');
         $email = $request->getPost('email', 'email');
         $name = strip_tags($name);
         $user->name = $name;
         $user->email = $email;
         if ($user->save() == false) {
             foreach ($user->getMessages() as $message) {
                 $this->flash->error((string) $message);
             }
         } else {
             $this->flash->success('更新成功');
         }
     }
 }
 /**
  * Handles login with either POST variables or remember me cookie values. 
  * If success redirects to dashboard (IndexController), unsuccesfull forward to index/loginform
  */
 public function loginAction()
 {
     $rememberMe = false;
     if ($this->request->isPost()) {
         $username = trim($this->request->getPost('username'));
         $password = trim($this->request->getPost('password'));
         $rememberMe = $this->request->getPost('rememberme');
     } else {
         if ($this->cookies->has('username') && $this->cookies->has('password')) {
             $username = trim($this->cookies->get('username')->getValue());
             $password = trim($this->cookies->get('password')->getValue());
         }
     }
     $user = Users::findFirst(array("username = :username:", 'bind' => array('username' => $username)));
     if ($user && $this->security->checkHash($password, $user->password)) {
         $this->_registerSession($user);
         $response = new Response();
         if ($rememberMe) {
             $response->setCookies($this->cookies->set('username', $username, strtotime('+1 year')));
             $response->setCookies($this->cookies->set('password', $password, strtotime('+1 year')));
         }
         $user->last_login = date('Y-m-d H:i:s');
         $user->save();
         return $response->redirect('');
     } else {
         $this->loginFailed = true;
     }
     return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
 }
Example #6
0
 /**
  * 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');
         }
     }
 }
 public function submitAction()
 {
     // Disable view
     $this->view->disable();
     // Check and get POSTED data
     if ($this->request->isPost() && !empty($login_name = $this->request->getPost("username")) && !empty($password = $this->request->getPost("password"))) {
         $user = Users::findFirst(array("login_name = :login_name: AND active = true", "bind" => array("login_name" => $login_name)));
         if (empty($user)) {
             echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Username tidak dikenal"));
             return;
         } else {
             if ($user->isBanned()) {
                 echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Username ini tidak dapat digunakan kembali"));
                 return;
             } else {
                 if ($user->isSuspended()) {
                     echo json_encode(array("success" => false, "errorType" => "username", "errorMessage" => "Untuk sementara, username ini tidak dapat digunakan"));
                     return;
                 }
             }
         }
         if (!$this->security->checkHash($password, $user->getPassword())) {
             echo json_encode(array("success" => false, "errorType" => "password", "errorMessage" => "Password yang anda masukkan salah"));
             return;
         }
         $this->session->set("auth", array("user" => $user, "role" => Roles::findFirstByIdRole($user->getIdRole())));
         echo json_encode(array("success" => true));
     }
 }
 /**
  * This action authenticate and logs a user into the application
  */
 public function startAction()
 {
     //die("session start action");
     if ($this->request->isPost()) {
         // Get the data from the user
         $nom = $this->request->getPost('name');
         $password = $this->request->getPost('password');
         //var_dump($nom . $password);die();
         // Find the user in the database
         $conditions = 'nom = :nom: AND mdp = :password:'******'bind' => array('nom' => $nom, 'password' => $password)));
         //var_dump($nom ."=>". $password);die("line 48");
         //var_dump($user);die("line 49");
         if ($user != false) {
             //die("coucou " . $nom);
             $this->_registerSession($user);
             $this->flash->success('Welcome ' . $user->nom);
             // Forward to the 'invoices' controller if the user is valid
             return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'listMembers'));
         }
         $this->flash->error('Wrong username/password');
     }
     // Forward to the login form again
     return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
 }
Example #9
0
 function indexAction()
 {
     $uid = $this->session->get('user');
     $user = Users::findFirst("id = '{$uid}'");
     $userLeagues = $user->userLeagues;
     $this->view->userLeagues = $userLeagues;
     echo $this->view->render('leagues', 'index');
 }
Example #10
0
 /**
  * 获取标签目标信息
  * @return unknown
  */
 public function getTarget()
 {
     if ($this->type == 1) {
         $target = Articles::findFirst($this->target_id);
     } elseif ($this->type == 2) {
         $target = Users::findFirst($this->target_id);
     }
     return $target;
 }
 public static function access()
 {
     $key = isset($_POST['key']) ? $_POST['key'] : die('Не передан обязательный параметр key');
     $user = Users::findFirst(array("key = :key:", 'bind' => array('key' => $key)));
     if ($user != false) {
         return true;
     } else {
         die('Неверный api_key');
     }
 }
Example #12
0
/**
 * Auth the actor role
 *
 * @param \Phalcon\Mvc\Micro $app
 * @return void
 */
function auth($app)
{
    $token = $app->request->get('token', 'string');
    /* @var Users $admin */
    $admin = Users::findFirst("id = " . ADMIN_USER_ID);
    if (!$admin || !$admin instanceof Users || $admin->token !== $token) {
        echo -999;
        die;
    }
}
 public function getUserAction()
 {
     $userId = $this->request->get('userId', 'int');
     $users = new Users();
     $user = $users->findFirst('id = ' . $userId)->toArray();
     if ($user) {
         $user['registered'] = date('d.m.Y H:i:s', $user['registered']);
     }
     $this->response->setContentType('application/json', 'utf-8');
     $this->response->setJsonContent($user);
     return $this->response;
 }
Example #14
0
 public function loginAction()
 {
     $login = $this->request->getPost('login');
     $password = $this->request->getPost('password');
     $user = Users::findFirst(array("login = ?0", "bind" => array($login)));
     if ($user) {
         if ($this->security->checkHash($password, $user->password)) {
             //The password is valid
         }
     }
     //The validation failed
 }
Example #15
0
 public function startAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $user = Users::findFirst(array("(email=:email: or username=:email:) and password=:password:", 'bind' => array('email' => $email, 'password' => sha1($password))));
         if ($user != false) {
             $this->_registerSession($user);
             $this->flash->success('Welcome' . $user->name);
             return $this->forward('invoices/index');
         }
     }
 }
 public function loginAction()
 {
     if ($this->request->isPost()) {
         $user = Users::findFirst(array('login = :login: and password = :password:'******'bind' => array('login' => $this->request->getPost("login"), 'password' => sha1($this->request->getPost("password")))));
         if ($user === false) {
             $this->flash->error("Incorrect credentials");
             return $this->dispatcher->forward(array('controller' => 'users', 'action' => 'index'));
         }
         $this->session->set('auth', $user->id);
         $this->flash->success("You've been successfully logged in");
     }
     return $this->dispatcher->forward(array('controller' => 'posts', 'action' => 'index'));
 }
 /**
  * 修改密码
  * @Post("/forget")
  */
 public function forgetAction()
 {
     $this->_validation->add('mobile', new Mobile(array('message' => '手机号码错误', 'cancelOnFail' => true)))->add('mobile', new Existence(array('message' => '手机号码没有注册过', 'model' => 'Users', 'cancelOnFail' => true)))->add('vcode', new Regex(array('pattern' => '/^\\d{6}$/', 'message' => '请输入验证码', 'cancelOnFail' => true)))->add('password', new StringLength(array('max' => 20, 'min' => 6, 'messageMinimum' => '密码长度最少6位(包括6位)', 'messageMaximum' => '密码长度不能大于20位(包括20位)')));
     $params = $this->validate();
     $keyName = self::FORGET_VCODE . $params['mobile'];
     if (!$this->checkVcode($keyName, $params['vcode'])) {
         throw new Exception('验证码错误', Messages::$ERROR_FORMAT);
     }
     $parameters = array();
     $parameters['conditions'] = sprintf('mobile = "%s"', $params['mobile']);
     $user = Users::findFirst($parameters);
     $this->save($user);
 }
Example #18
0
 public function viewsAction()
 {
     $products = Real::findFirst($this->dispatcher->getParam("id"));
     $this->tag->setTitle('Купить - ' . $products->name . ' по лучшей цене ' . $products->price . ' руб.');
     parent::initialize();
     $this->view->product = $products;
     $di_id = $this->dispatcher->getParams("id");
     $this->view->id = $di_id['id'];
     $author = Users::findFirst($products->user_id);
     $this->view->author_name = $author->name;
     $this->view->author_phone = $author->phone;
     $this->view->author_email = $author->email;
     $this->view->author_day = intval((strtotime(date("Y-m-d H:i:s")) - strtotime($author->created_at)) / (60 * 60 * 24));
 }
Example #19
0
 /**
  * Authenticate user by login/password pair
  * @param bool|false $login
  * @param bool|false $password
  * @return bool|\Phalcon\Mvc\Model
  */
 public function authByCredentials($login = false, $password = false)
 {
     $users = new Users();
     $user = $users->findFirst("login='******'");
     if (!$user) {
         return false;
     }
     if (!$this->security->checkHash($password, $user->password)) {
         return false;
     }
     $user->token = $this->security->getToken(16);
     $cookieWrote = $this->writeCookie($user->token);
     return $user->update() && $cookieWrote ? $user : false;
 }
 public function setupAction()
 {
     $request = new Request();
     if ($request->isPost()) {
         $password = $request->getPost('password');
         $userType = $request->getPost('userType');
         $user = Users::findFirst("type = '" . $userType . "'");
         if (!$user) {
             $user = new Users();
             $user->setType($userType);
         }
         $user->setPass($this->security->hash($password));
         $user->save();
     }
 }
Example #21
0
 /**
  * This action authenticate and logs an user into the application
  *
  */
 public function startAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost('name');
         $password = $this->request->getPost('password');
         $user = Users::findFirst(array("(email = :email: OR username = :email:) AND password = :password: AND active = 'Y'", 'bind' => array('email' => $email, 'password' => sha1($password))));
         if ($user != false) {
             $this->_registerSession($user);
             $this->flash->success('Welcome ' . $user->name);
             return $this->forward('index/index');
         }
         $this->flash->error('Wrong email/password');
     }
     return $this->forward('session/index');
 }
 public function updateAction($userId)
 {
     // When submit information of user
     if ($this->request->isPost()) {
         $updateUser = Users::findFirst($this->request->get("id"));
         $updateUser->firstname = $this->request->get("first_name");
         $updateUser->lastname = $this->request->get("last_name");
         $updateUser->bithday = $this->request->get("date");
         $updateUser->save();
         return $this->dispatcher->forward(array('action' => 'index'));
     } else {
         // When click to select user to update
         $this->view->user = Users::findFirst($userId);
     }
 }
Example #23
0
 /**
  * This action authenticate and logs an user into the application
  *
  */
 public function startAction()
 {
     $response = new \Phalcon\Http\Response();
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $user = Users::findFirst(array("(email = :email: OR username = :email:) AND password = :password: AND active = 'Y'", 'bind' => array('email' => $email, 'password' => sha1($password))));
         if ($user != false) {
             $this->_registerSession($user);
             return $response->redirect();
         }
         $this->flash->error('Неверный email/пароль');
         return $this->forward('login/index');
     }
     return $response->redirect();
 }
Example #24
0
 public function loginAction()
 {
     if ($this->request->isPost()) {
         //Receiving the variables sent by POST
         $username = $this->request->getPost('username');
         $password = $this->request->getPost('password');
         //Find the user in the database
         $user = Users::findFirst(array("username = :username: AND password = :password: "******"bind" => array('username' => $username, 'password' => md5($password))));
         if ($user != false) {
             $this->_registerSession($user);
             $response = new \Phalcon\Http\Response();
             return $response->redirect("admin");
         } else {
             $this->flash->error('Wrong email/password');
         }
     }
 }
 /**
  * start validate user action
  */
 public function startAction()
 {
     if ($this->request->isPost()) {
         // get user and password from form
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         // Find user in the database return Users if exist or false if not
         $user = Users::findFirst(array("(email = :email: ) and password = :password:"******"Wrong email/password");
         $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
     }
 }
Example #26
0
 public function editAction()
 {
     $this->tag->setTitle('Редактирование профиля');
     parent::initialize();
     $auth = $this->session->get('auth');
     $profile = $auth['id'];
     $get_id = $this->dispatcher->getParam("id");
     if ($profile != $get_id) {
         $this->flash->error("Нет прав редактирования!");
         $this->view->prof_user = false;
     } else {
         $this->view->prof_user = true;
         $profile = Users::findFirst($this->dispatcher->getParam("id"));
         $this->view->prof_username = $profile->username;
         $this->view->prof_email = $profile->email;
         $this->view->prof_name = $profile->name;
         $this->view->prof_phone = $profile->phone;
         $profile_sale = Buyers::findByid_users($this->dispatcher->getParam("id"));
         $this->view->prof_sex = $profile->sex;
         /*Если есть данные, то сохраняем*/
         if ($this->request->isPost()) {
             $user = Users::findFirst($auth['id']);
             $old_password = sha1($this->request->getPost('old_password'));
             $password = $user->password;
             if ($old_password == $password && $old_password != '') {
                 if ($this->request->getPost('password') != '') {
                     $user->password = sha1($this->request->getPost('password'));
                 }
                 $user->id = $auth['id'];
                 $user->email = $this->request->getPost('email');
                 $user->phone = $this->request->getPost('phone');
                 $user->sex = $this->request->getPost('sex');
                 if ($user->update() == false or $old_password != $password) {
                     foreach ($user->getMessages() as $message) {
                         $this->flash->error((string) $message);
                     }
                 } else {
                     $this->flash->success('Данные успешно сохранены');
                 }
             }
         }
     }
 }
 /**
  * This actions receives the input from the login form
  *
  */
 public function loginAction()
 {
     $this->view->disable();
     if ($this->request->isPost()) {
         $username = $this->request->getPost('username', 'email');
         $password = $this->request->getPost('password');
         $password = sha1($password);
         $conditions = 'username = :username: AND password = :password:'******'username' => $username, 'password' => $password);
         $user = Users::findFirst(array($conditions, 'bind' => $parameters));
         if ($user != false) {
             $this->registerSession($user);
             $this->flash->success('Welcome ' . $user->name);
             return $this->response->redirect('');
         }
         $this->flash->error('Wrong username/password combination');
     }
     return $this->response->redirect('');
 }
 public function startAction()
 {
     if ($this->request->isPost()) {
         //Taking the variables sent by POST
         $email = $this->request->getPost('email', 'email');
         $password = $this->request->getPost('password');
         $password = sha1($password);
         //Find for the user in the database
         $user = Users::findFirst(array("email = :email: AND password = :password: AND active = 'Y'", "bind" => array('email' => $email, 'password' => $password)));
         if ($user != false) {
             $this->_registerSession($user);
             $this->flash->success('Welcome ' . $user->name);
             //Forward to the 'invoices' controller if the user is valid
             return $this->dispatcher->forward(array('controller' => 'invoices', 'action' => 'index'));
         }
         $this->flash->error('Wrong email/password');
     }
     //Forward to the login form again
     return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'index'));
 }
Example #29
0
 public function publishAction(array $params)
 {
     if (isset($params[0])) {
         $id = $params[0];
         $sms_data = SmsHistory::findFirst("id ='{$id}' AND status ='PENDING'");
         if ($sms_data) {
             $user_id = $sms_data->user_id;
             $user = Users::findFirst("id = '{$user_id}'");
             if ($user->smsbalance->balance >= $sms_data->billcredit) {
                 switch ($sms_data->type) {
                     case 'GROUPID':
                         $result = Groups::getGroupNumber(json_decode($sms_data->reciever));
                         break;
                     case 'NUMBER':
                         $result = implode(',', json_decode($sms_data->reciever));
                         break;
                     case 'CONTACTID':
                         $result = Contacts::getNumbers(json_decode($sms_data->reciever));
                         break;
                 }
                 $data = $this->sendSMSRequest(array("message" => urldecode($sms_data->message), 'sender_id' => $user->sender_id, 'contacts' => explode(',', $result)));
                 $sms_data->status = "SUCCESS";
                 $user->smsbalance->balance = $user->smsbalance->balance - $sms_data->billcredit;
                 $user->smsbalance->used = $user->smsbalance->used + $sms_data->billcredit;
                 $user->smsbalance->save();
             } else {
                 $sms_data->status = "FAILED";
             }
             $sheduled_sms = SheduleSms::findFirst("sms_id = '{$id}'");
             if ($sheduled_sms->id) {
                 $sheduled_sms->delete();
             }
             $sms_data->created_at = date("Y-m-d H:i:s");
             $sms_data->updated_at = date("Y-m-d H:i:s");
             $sms_data->save();
         } else {
             echo "\n Task Not Found \n";
         }
     }
 }
Example #30
0
 public function get_all_permissions()
 {
     // $request = $this->get_request();
     // $id_user = $request->id;
     $id_user = 1;
     $role_acos = array();
     $user = Users::findFirst($id_user);
     foreach ($user->RolesUsers as $rol_usuario) {
         $roles = Roles::findFirst($rol_usuario->getIdRole());
         foreach ($roles->RolesPermissions as $rol_permission) {
             $role_acos[] = $rol_permission->Permissions->getIdAco();
         }
     }
     $user_acos = array();
     $user = Users::findFirst($id_user);
     foreach ($user->UsersPermissions as $user_permission) {
         $user_acos[] = $user_permission->Permissions->getIdAco();
     }
     $merge_permissions = array_merge($role_acos, $user_acos);
     $result = array_unique($merge_permissions);
     return $result;
 }