Example #1
0
 /**
  * GPS安装
  */
 public function gpsAction()
 {
     if ($this->isAjax()) {
         $data = $this->request->getPost();
         $uid = $data['uid'];
         !$uid and $this->error('参数错误');
         $data['gps'] = 1;
         $model = new LoanForm('gps');
         if ($result = $model->validate($data)) {
             if ($model->sign()) {
                 Log::add($uid, $this->getOperatorId(), \App\Config\Log::loanOperate('gps'));
                 $this->success('操作成功');
             } else {
                 $this->error('操作失败');
             }
         } else {
             $this->error('验证失败');
         }
         exit;
     }
     $uid = $this->urlParam();
     empty($uid) and $this->pageError('param');
     $loan = Loan::findByUid($uid);
     $user = User::findFirst($uid)->toArray();
     $this->view->setVars(['loan' => $loan, 'user' => $user]);
     $this->view->pick('afterrc/detail');
 }
Example #2
0
 public static function find_by_name($username)
 {
     $conditions = "username = :name:";
     $parameters = array("name" => $username);
     $user = User::findFirst(array($conditions, "bind" => $parameters));
     return $user;
 }
 public function indexAction()
 {
     if ($this->request->hasPost('up')) {
         $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     }
     if ($this->session->has('user_id')) {
         $id = $this->session->get('user_id');
         $user = User::findFirst($id);
         foreach ($user->offers as $offers) {
             $image = unserialize($offers->image);
             if (isset($image['image-big-1'])) {
                 $im = 1;
             } else {
                 $im = 0;
             }
             $off[$offers->id]['name'] = array($offers->name, $im, $offers->status, $offers->user->phone, $offers->categories->name);
             if (isset($offers->id)) {
                 foreach ($offers->dannoffers as $dan) {
                     $off[$offers->id][$dan->fieldtype->id] = $dan->dann;
                 }
             }
         }
     }
     //  $this->elements->var_print($off);
     $this->view->setVars(array("cn" => count($user->offers), "off" => $off = isset($off) ? $off : false));
 }
Example #4
0
 /**
  * Login action, detect if is a valid or invalid user
  */
 public function loginAction()
 {
     $form = new LoginForm();
     if ($this->request->isPost()) {
         if ($form->isValid($this->request->getPost()) != false) {
             $password = $this->request->getPost('password');
             //Find the username and check if this is active into the application
             $user = User::findFirst(array("username = :username: AND active = 1", 'bind' => array('username' => strtolower($this->request->getPost('username', 'striptags')))));
             // successfully find
             if ($user && $this->security->checkHash($password, $user->password)) {
                 //Sent the user to set into the application
                 $this->auth->setAccess($user);
                 //Remember me: If is diferent to false assign a token to the user
                 if ($this->request->getPost('remember') != "false") {
                     $user->assign(array('token' => $this->request->getPost('remember')));
                     if (!$user->save()) {
                         $this->flash->error($user->getMessages());
                     }
                 }
                 return $this->response->redirect('dashboard');
             } else {
                 $form->addFormMessages('username', 'Username name is invalid or not has been activated');
                 $form->addFormMessages('password', 'information does not match');
             }
         }
     }
     $this->view->form = $form;
 }
Example #5
0
 /**
  * @Route("/login", methods = {"POST", "OPTIONS"})
  */
 public function LoginAction()
 {
     //Post传过来的是一个无名的json数据,所以只能getRawBody
     $info = $this->request->getJsonRawBody();
     if (!isset($info->username) || !isset($info->password)) {
         $this->response->setJsonContent(['message' => 'No Data!']);
         $this->response->send();
         return;
     }
     $username = $info->username;
     $password = $info->password;
     $user = User::findFirst(['conditions' => 'name=?1', 'bind' => [1 => $username]]);
     if ($user == null) {
         $this->response->setJsonContent(['message' => '用户不存在']);
     } elseif ($user->password != $password) {
         $this->response->setJsonContent(['message' => '密码错误']);
     } else {
         //            $this->session->set('user_id', $user_array['id']);
         //            $this->session->set('user_name', $user_array['name']);
         //            $this->session->set('user_role', $user_array['role']);
         $this->response->setJsonContent(['user_id' => $user->id, 'user_name' => $user->name, 'user_role' => $user->role]);
     }
     $this->response->send();
     return;
 }
 public function confirmAction()
 {
     $this->view->disable();
     $mail = $this->dispatcher->getParam('mail');
     $user = User::findFirst(array('conditions' => 'mail = ?1', 'bind' => array(1 => $mail)));
     if ($user) {
         $conf = Confirmation::findFirst(array('conditions' => 'user = ?1', 'bind' => array(1 => $user->id)));
         if ($conf) {
             if ($conf->code == $this->dispatcher->getParam('code')) {
                 $user->confirmed = 1;
                 if ($user->save()) {
                     $this->_login($user);
                     $conf->delete();
                     message($this, "s", "Аккаунт подтвержден. Добро пожаловать, " . $user->name);
                     return $this->response->redirect();
                 } else {
                     message($this, "d", "Ошибка активации. Попробуйте позже");
                     return $this->response->redirect();
                 }
             } else {
                 message($this, "d", "Код подтверждения не подходит");
                 return $this->response->redirect();
             }
         } else {
             message($this, "w", "Пользователь уже подтвержден");
             return $this->response->redirect();
         }
     } else {
         message($this, "d", "Пользователя " . $mail . " не существует");
         return $this->response->redirect();
     }
 }
 public function indexAction()
 {
     $this->view->products = Product::find();
     if ($this->session->get("auth")) {
         $this->view->user = User::findFirst($this->session->get("auth")['id']);
     }
 }
Example #8
0
 public function mapAction($idVisit)
 {
     $visit = Visit::findFirst(array("conditions" => "idVisit = ?1", "bind" => array(1 => $idVisit)));
     if (!$visit) {
         $this->flashSession->error("Ocurrio un error procesando su solicitud, por favor intentelo nuevamente.");
         return $this->response->redirect('index');
     }
     $user = User::findFirst(array("conditions" => "idUser = ?1 AND idAccount = ?2", "bind" => array(1 => $visit->idUser, 2 => $this->user->idAccount)));
     if (!$user) {
         $this->flashSession->error("Ocurrio un error procesando su solicitud, por favor intentelo nuevamente.");
         return $this->response->redirect('visit/index');
     }
     try {
         $sql_rows = "SELECT v.idVisit AS idUser, v.start AS date, u.name AS name, u.lastName AS lastname, vt.name AS visit, c.name AS client, v.battery AS battery, v.latitude AS latitude, v.longitude AS longitude, v.location AS location " . "FROM Visit AS v " . " JOIN User AS u ON (u.idUser = v.idUser) " . " JOIN Visittype AS vt ON (vt.idVisittype = v.idVisittype) " . " JOIN Client AS c ON (c.idClient = v.idClient) " . " WHERE v.idVisit = {$idVisit}";
         //            $this->logger->log($sql_rows);
         $modelsManager = \Phalcon\DI::getDefault()->get('modelsManager');
         $rows = $modelsManager->executeQuery($sql_rows);
         $this->view->setVar('visit', $rows->getFirst());
         $this->view->setVar('user', $user);
     } catch (Exception $e) {
         $this->flashSession->error($e->getMessage());
         $this->trace("fail", $e->getMessage());
         return $this->response->redirect('visit/index');
     }
 }
Example #9
0
 public function tryLogin($data)
 {
     // Reject requests
     if ($this->isExceedingRateLimit(2)) {
         $this->response->setStatusCode(429, 'Too many requests');
         $this->flash->notice('Too many requests.');
         return false;
     }
     /** @var User $user */
     $user = User::findFirst(['email = :email:', 'bind' => ['email' => $data['user']]]);
     // Sleep for 1-500ms
     usleep(mt_rand(1000, 500000));
     if ($user && $user->validatePassword($data['password'])) {
         // Validate TOTP token
         // This needs to be done at this stage as the two factor auth key is
         // encrypted with the user's password.
         if ($otpKey = $user->getOtpKey($data['password'])) {
             $otp = new \Rych\OTP\TOTP($otpKey);
             if (!$otp->validate($data['token'])) {
                 $this->flash->error('Incorrect login details');
                 return false;
             }
         }
         $keyService = new \Stecman\Passnote\AccountKeyService();
         $keyService->unlockAccountKeyForSession($user, $data['password']);
         $this->session->set(Security::SESSION_USER_ID, $user->id);
         $this->session->set(Security::SESSION_KEY, $user->getSessionKey());
         session_regenerate_id();
         $this->response->redirect('');
     } else {
         // Keep timing
         $this->security->hash(openssl_random_pseudo_bytes(12));
         $this->flash->error('Incorrect login details');
     }
 }
Example #10
0
 protected function getUser()
 {
     static $user;
     if (!$user && ($auth = $this->getAuth()) && $auth['user_id']) {
         $user = User::findFirst(array('conditions' => 'id = ?1', 'bind' => array(1 => $auth['user_id'])));
     }
     return $user;
 }
Example #11
0
 /**
  * @return \User
  */
 public static function getCurrentUser()
 {
     $di = \Phalcon\DI::getDefault();
     $session = $di->get('session');
     if ($id = $session->get(self::SESSION_USER_ID)) {
         return User::findFirst($id);
     }
 }
Example #12
0
 public function onConstruct()
 {
     $userid = \User::check_token();
     $user = \User::findFirst([['userid' => $userid]]);
     if ($user) {
         $this->user = $user->attrs();
     }
 }
Example #13
0
 public function detailAction()
 {
     $uid = $this->urlParam();
     empty($uid) and $this->pageError('param');
     $loan = Loan::findByUid($uid);
     $user = User::findFirst($uid)->toArray();
     $this->view->setVars(['loan' => $loan, 'user' => $user]);
 }
 public function createAssocAction()
 {
     $user = User::findFirst();
     $project = new Project();
     $project->user = $user;
     $project->title = "Moon walker";
     $result = $project->save();
 }
Example #15
0
 public function principalAction()
 {
     $username = "******";
     $token = "ly4b35jvokj7cik9541ug6weqgjsjor";
     $user = User::findFirst(array("username = :username: and token = :token: AND active = 1", 'bind' => array('username' => strtolower($username), 'token' => $token)));
     if ($user == null) {
         echo "Como tal";
     }
     print_r($user);
 }
 /**
  * @param $filters
  * Param should assoc array in json format
  */
 public function getAction($filters)
 {
     $filters = json_decode($filters, true);
     $owner_id = isset($filters[WifiSpot::COL_OWNER_ID]) ? $filters[WifiSpot::COL_OWNER_ID] : null;
     $owner = User::findFirst($owner_id);
     $res = $owner->WifiSpot->toArray();
     $responseData = array('wifi_spots' => $res);
     $this->setOkStatus();
     $this->sendResponse($responseData);
 }
 public function ProjectsAction($id = NULL)
 {
     $user = User::findFirst("id=" . $id);
     $uses = Usecase::find("idDev=" . $id);
     foreach ($u as $uses) {
         //progressbar
         $avancement = $u->getAvancement();
         $this->jquery->bootstrap()->htmlProgressbar($u->getCode(), "success", $avancement)->setStriped(true)->setActive(true)->showcaption(true);
     }
     $this->jquery->compile($this->view);
     $this->view->setVars(array("user" => $user, "usecases" => $uses, "siteUrl" => $this->url->getBaseUri(), "baseHref" => $this->dispatcher->getControllerName()));
 }
 public function messageformAction($id = NULL, $nom, $nomfrm, $idFil)
 {
     $p = $this->getInstance($id);
     $user = User::findFirst();
     $message = Message::find("idProjet=" . $p->getId() . " AND idFil is NULL");
     foreach ($message as $msg) {
         $reponse = Message::find("idFil=" . $msg->getId());
     }
     $this->view->setVars(array("message" => $message, "reponse" => $reponse, "projet" => $p, "user" => $user, "nom" => $nom, "idFil" => $idFil, "nomfrm" => $nomfrm));
     $this->jquery->postFormOnClick(".validate", "Messages/repondre", "frmAjoutMessage", "#divMessages");
     $this->jquery->compile($this->view);
 }
 public function startAction()
 {
     $email = $_POST['email'];
     $password = $_POST['password'];
     $user = User::findFirst(array("(email = :email: OR username = :email:)", 'bind' => array('email' => $email)));
     if (password_verify($password, $user->password)) {
         $this->_registerSession($user);
         $this->flash->success('Welcome ' . $user->name);
         return $this->response->redirect('index');
     }
     $this->flash->error('Wrong email/password');
     return $this->response->redirect('Session/index');
 }
Example #20
0
 public function fastConnectAction($role)
 {
     $user = User::findFirst("idRole = " . $role);
     if ($user != null) {
         $this->session->set("user", $user);
         $acl = Acl::find("idRole = " . $user->getIdRole());
         $this->session->set("rights", AclController::toArray($acl));
         $msg = new DisplayedMessage("Bienvenue " . $user);
         $this->dispatcher->forward(array("controller" => "Index", "action" => "indexAjax", "params" => array($msg)));
     } else {
         $this->dispatcher->forward(array("controller" => "Auth", "action" => "signin", "params" => array(true)));
     }
 }
Example #21
0
 public static function editByUid($uid, $data)
 {
     $uinfo = User::findFirst($uid);
     if (!$uinfo) {
         return false;
     }
     foreach ($data as $field => $value) {
         $uinfo->{$field} = $value;
     }
     if ($uinfo->update()) {
         return true;
     }
 }
Example #22
0
 /**
  * try to find de correct remenber me info...
  * @param username String: Username sent by ajaxPost
  * @param token String: token sent by ajaxPost
  * @return true: success remember; false: incorrect info!;
  */
 public function appRemember($username, $token)
 {
     try {
         $user = User::findFirst(array("username = :username: and token = :token: AND active = 1", 'bind' => array('username' => strtolower($username), 'token' => $token)));
         if ($user != null) {
             $this->setAccess($user);
             return true;
         } else {
             return false;
         }
     } catch (Exception $e) {
     }
     return false;
 }
Example #23
0
 public function indexAction()
 {
     if ($this->request->isPost()) {
         $params = $this->request->getPost();
         if ($this->_validation($params)) {
             $user = User::findFirst(array('(user = :user: OR name = :user: OR email = :user:) AND password = :password: AND active = 1', 'bind' => array('user' => $params['user'], 'password' => md5($params['password']))));
             if ($user != false) {
                 $this->_registerSession($user);
                 $this->flash->success('Xin chào ' . $user->name);
                 return $this->forward('admin');
             } else {
                 $this->flash->error('Tên hoặc mật khẩu không đúng !');
             }
         }
     }
 }
 /**
  * This action authenticate and logs an user into the application
  *
  */
 public function loginAction()
 {
     $this->view->setTemplateBefore('public');
     if ($this->request->isPost()) {
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $user = User::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->username);
             return $this->response->redirect('user/index');
         }
         $this->flash->error('Wrong email/password' . $user);
         return $this->response->redirect('session/login');
     }
 }
 public function indexAction()
 {
     if ($this->request->hasPost('od') && $this->request->getPost('od') == 'y') {
         $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     }
     if ($this->session->has('user_id')) {
         $user_id = $this->session->get('user_id');
         $user = User::findFirst($user_id);
         foreach ($user->proposal as $prop) {
             foreach ($prop->dannproposal as $dann) {
                 $props[$prop->id][$dann->fieldtype->id] = $dann->dann;
                 $props[$prop->id]['cat'] = $prop->categories->name;
             }
         }
         $this->view->setVars(array('cl' => count($user->proposal), 'prop' => $props = isset($props) ? $props : false));
     }
 }
Example #26
0
 public function prosesloginAction()
 {
     if ($this->request->isPost()) {
         $username = $this->request->getPost('username');
         $password = $this->request->getPost('password');
         $tbluser = User::findFirst(array('username' => '$username'));
         if ($tbluser) {
             if ($password == $tbluser->password) {
                 $this->session->set("level", $tbluser->level_user);
                 $this->response->redirect('index');
             }
         } else {
             echo "Username atau password salah";
             return $this->dispatcher->forward(array("action" => "index"));
         }
     }
 }
 /**
  * @api {put} /user 更新当前登录用户信息
  * @apiUse header
  *
  * @apiName updateUser
  * @apiGroup User
  * @apiVersion 1.0.0
  *
  * @apiParam {String} username 该子会议的ID
  * @apiParam {String} name 该子会议名称 必选
  * @apiParam {String} organization 子会议的开始时间
  * @apiParam {Integer} title 子会议的结束时间
  * @apiParam {String} email 子会议举行场地
  * @apiParam {String} password 该子会议可接纳的人数
  *
  * @apiSuccess {Array} empty_array 空数组
  */
 public function updateUser()
 {
     $token = $this->session->get('token');
     // username name organization title email password
     $data = $this->request->get();
     $dbUser = User::findFirst('id=' . $token->user_id);
     if (!empty($data['password'])) {
         $data['password'] = password_hash($data['password'], PASSWORD_DEFAULT);
     }
     $dbUser = $dbUser->toArray();
     $userModel = new User();
     if (false == $userModel->save(array_merge($dbUser, $data))) {
         // 使用修改的数据覆盖原始的数据来达到部分更新效果
         return parent::resWithErrMsg($userModel->getMessages());
     }
     return parent::success();
 }
Example #28
0
 /**
  * Set the password of an existing user
  *
  * @param $email
  */
 public function set_passwordAction($email)
 {
     /** @var User $user */
     $user = User::findFirst(['email = :email:', 'bind' => ['email' => $email]]);
     if ($user) {
         $oldPassword = $this->promptInput('Current password:', true);
         if (!$user->validatePassword($oldPassword)) {
             die("Password incorrect\n");
         }
         $newPassword = $this->promptCreatePassword(true);
         $user->changePassword($oldPassword, $newPassword);
         $this->db->begin();
         $user->getAccountKey()->save();
         $user->save();
         $this->db->commit();
         echo "Password updated.\n";
     } else {
         die("No user found for {$email}\n");
     }
 }
 public function projectAction($id = NULL)
 {
     $p = Projet::findFirst("id=" . $id);
     $user = User::findFirst("id=" . $p->getIdAuthor());
     //g�n�ration des progress barre pour chaque usecase
     foreach ($usecases as $u) {
         //progressbar
         $avancement = $u->getAvancement();
         $this->jquery->bootstrap()->htmlProgressbar($u->getCode(), "success", $avancement)->setStriped(true)->setActive(true)->showcaption(true);
     }
     //image a mettre
     if ($p->getImage() == NULL) {
         $source = "../../public/img/increase.png";
     } else {
         $source = $p->getImage();
     }
     $this->jquery->getOnClick(".afficher", "", "#detailProject", array("attr" => "data-ajax", "jsCallback" => "\$('#detailProject').slideToggle('slow');"));
     $this->jquery->compile($this->view);
     $this->view->setVars(array("project" => $p, "user" => $user, "source" => $source, "siteUrl" => $this->url->getBaseUri(), "baseHref" => "Projects"));
 }
Example #30
-2
 /**
  * 确认放款
  */
 public function confirmAction($uid)
 {
     if ($this->isAjax()) {
         !$uid and $this->error('参数错误');
         if (Loan::updateStatus($uid, \App\LoanStatus::getStatusRunConfirm())) {
             Log::add($uid, $this->getOperatorId(), \App\Config\Log::loanOperate('runconfirm'));
             $this->success('操作成功');
         }
         $this->error('操作失败');
     }
     $loan = Loan::findByUid($uid);
     $user = User::findFirst($uid)->toArray();
     $this->view->setVars(['loan' => $loan, 'user' => $user]);
     $this->view->pick('run/detail');
 }