Пример #1
0
 public function changeroleAction()
 {
     $user = $this->userService->getUser((int) $this->_getParam('id'));
     if (!$user) {
         $this->flash("Cannot change role for that user");
         $this->redirect('admin', 'userlist');
     }
     $this->userService->setUserRole($user, $this->_getParam('role'));
     $this->redirect('admin', 'userlist');
 }
Пример #2
0
 /**
  * Add a bunch of users to a group
  *
  * @param UserGroup $group
  * @param array $userids
  */
 public function addUsersToGroup(UserGroup $group, array $userids)
 {
     $this->dbService->beginTransaction();
     $this->emptyGroup($group);
     foreach ($userids as $userid) {
         $this->log->debug("Adding user {$userid} to group {$group->id}");
         $user = $this->userService->getUser($userid);
         $this->addToGroup($group, $user);
     }
     $this->dbService->commit();
 }
Пример #3
0
 /**
  * Show a form to edit a particular user.
  *
  * @param integer $id The id of the user to edit.
  *
  * @return mixed The response.
  */
 public function showEditUser($id)
 {
     try {
         $user = UserService::getUser($id);
         $data = array('user' => $user);
         $data = array_merge_recursive($data, $this->getCommonData());
         return View::make('users.edit', $data);
     } catch (Exception $e) {
         return $this->unexpected($e);
     }
 }
Пример #4
0
/**
 * 登录处理
 */
function do_login()
{
    $userName = $_REQUEST['userName'];
    $password = md5($_REQUEST['password']);
    $rememberMe = $_REQUEST['rememberMe'];
    $userService = new UserService();
    $userId = $userService->checkPassword($userName, $password);
    // 检查cookie中是否设置了“记住我”
    $isCookieLogin = false;
    if (isset($_COOKIE['rememberMe'])) {
        $userId = (int) substr($_COOKIE['rememberMe'], 0, 1);
        $isCookieLogin = true;
    }
    if ($userId == -1) {
        // 用户名或密码不存在
        $output = array('result' => 'wrongUserNamePassword');
        echo get_json($output);
    } else {
        // 登录处理
        $result = $userService->getUser($userId);
        $code = '0';
        $redirect = '';
        if ($result != null) {
            $_SESSION['userId'] = $result['user_id'];
            $_SESSION['userDetail'] = $result;
            // 用户数据
            // 将用户名保存至cookie
            setcookie('userName', $result['user_name'], time() + 60 * 60 * 24 * 30, '/');
            // “记住我”流程补充
            if ($rememberMe == 1) {
                $saveVal = $_SESSION['userId'] . md5($_SESSION['userId']);
                setcookie('rememberMe', $saveVal, time() + 60 * 60 * 24 * 30, '/');
            } else {
                setcookie('rememberMe', '', time() - 3600, '/');
            }
            $code = '0';
            if (isset($_SESSION['lastUrl'])) {
                $redirect = $_SESSION['lastUrl'];
            } else {
                $redirect = DOMAIN_NAME . '/' . APP_NAME . '/index.php';
            }
        } else {
            $code = 'wrongUserNamePassword';
        }
        $output = array('retCode' => $code, 'redirect' => $redirect);
        echo get_json($output);
        if ($isCookieLogin == true) {
            header('location: ' . $redirect);
            exit;
        }
    }
}
Пример #5
0
 /**
  * Process settings form.
  *
  * @return Illuminate\View\View A view.
  */
 public function processSettings()
 {
     try {
         $user = UserService::getUser(Auth::user()->id);
         $user->locale_id = Input::get('locale');
         unset($user->password);
         UserService::updateUser(Auth::user()->id, $user);
         $this->success(trans('messages.settingsSaved'));
         return Redirect::to('settings');
     } catch (Exception $e) {
         return $this->unexpected($e);
     }
 }
Пример #6
0
 /**
  * Save a leave application
  */
 public function saveapplicationAction()
 {
     $user = $this->userService->getUser((int) $this->_getParam('userid'));
     try {
         $this->_setParam('username', $user->getUsername());
         $params = $this->filterParams();
         $model = $this->userService->applyForLeave($user, $params);
     } catch (InvalidModelException $ime) {
         $this->flash($ime->getMessages());
         $model = new LeaveApplication();
         $model->bind($this->_getAllParams());
         $this->applyAction($model);
         return;
     }
     $this->onModelSaved($model);
 }
Пример #7
0
 /**
  * View a user and their session booking details. 
  *
  */
 public function viewAction()
 {
     $id = (int) $this->_getParam('id');
     $user = za()->getUser();
     if (!$id) {
         $viewUser = $user;
     } else {
         $viewUser = $this->userService->getUser($id);
     }
     // If the user isn't the same as the current user,
     // we need to be an admin to view it
     if ($viewUser->id != $user->id && $user->getRole() != 'Admin') {
         $this->view->flash("You must be logged in as an administrator to view that");
         $this->redirect('user', 'login');
         return;
     }
     // Okay, load up the user view page then!
     $this->view->user = $viewUser;
     $this->renderView('user/view.php');
 }
Пример #8
0
function userLogin($username, $user_password)
{
    // Open a connection to the database
    try {
        $pdo = new PDO(DB_PDODRIVER . ':host=' . DB_HOST . ';dbname=' . DB_NAME . '', DB_USER, DB_PASS);
    } catch (\PDOException $e) {
        echo "Connection failed: " . $e->getMessage();
        exit;
    }
    // Create a new instance of UserService
    $login_service = new UserService($pdo, $username, $password);
    // Set user_id equal to login()
    if ($user_id = $login_service->login()) {
        $user_data = $login_service->getUser();
        $pdo = null;
        header('Location: ../index.php');
    } else {
        $pdo = null;
        header('Location: ../error.php?error=login');
    }
}
Пример #9
0
function login($req)
{
    $emailOrTel = trim($req['user']);
    $password = $req['password'];
    $response['status'] = 0;
    if (empty($emailOrTel) || empty($password)) {
        $response['msg'] = "用户名密码格式错误";
        echo json_encode($response);
        return;
    }
    $user['user'] = $emailOrTel;
    $user['password'] = $password;
    $res = UserService::getUser($user);
    if (empty($res) || count($res) <= 0) {
        $response['msg'] = "用户名密码错误";
        echo json_encode($response);
        return;
    }
    $response['status'] = 1;
    setSessionCookie($res);
    echo json_encode($response);
}
Пример #10
0
 public function milestoneslistAction()
 {
     $project = $this->projectService->getProject((int) $this->_getParam('projectid'));
     if ($project == null) {
         $this->flash("Project not found");
         $this->renderRawView('error.php');
         return;
     }
     $this->view->projectuser = za()->getUser();
     if ($this->_getParam('projectuser')) {
         if ($this->_getParam('projectuser') == 'all') {
             $this->view->projectuser = null;
         } else {
             $this->view->projectuser = $this->userService->getUser($this->_getParam('projectuser'));
         }
     }
     $this->view->groupusers = $project->getUsers();
     if ($this->view->projectuser && !isset($this->view->groupusers[$this->view->projectuser->id])) {
         $this->view->projectuser = null;
     }
     $this->view->project = $project;
     $this->renderRawView('project/milestone-list.php');
 }
 /**
  * @test
  */
 public function it_returns_null_when_a_user_can_not_be_found_by_id()
 {
     $this->cultureFeed->expects($this->once())->method('getUser')->with(1, UserService::INCLUDE_PRIVATE_FIELDS)->willThrowException(new \CultureFeed_ParseException('error'));
     $user = $this->service->getUser(1);
     $this->assertNull($user);
 }