/**
  * Display listing of the resource
  *
  * @return Response
  */
 public function login()
 {
     //set the user array to gather data from user form
     $userdata = array('username' => Input::get('username'), 'password' => Input::get('password'));
     /*
     $hashpassword = Hash::Make(Input::get('password'));
     var_dump($hashpassword);
     die();
     */
     if (Auth::check()) {
         return Redirect::to('/');
     }
     if (Auth::attempt($userdata)) {
         // cauta userul in baza de date
         $user = UserModel::find(Auth::user()->id);
         if ($user->active == 0) {
             //daca userul nu este activ
             Auth::logout();
             Session::flush();
             return Redirect::to('login')->with('message', FlashMessage::DisplayAlert('Login successful', 'success'));
         }
         //if($user->active == '0')
         //daca userul este activ
         Session::put('current_user', Input::get('username'));
         Session::put('user_access', $user->access);
         Session::put('user_id', $user->id);
         return Redirect::to('/');
     } else {
         return Redirect::to('login')->with('message', FlashMessage::DisplayAlert('Incorrect username or password', 'danger'));
     }
     //else if Auth
 }
Example #2
0
 public function areatoname()
 {
     $userInfo = UserModel::find($this->uid);
     $areaName = $userInfo->area ? $this->getAreaName($userInfo->area) : '';
     //        return $userInfo->area ? AreaModel::find($userInfo->area)->cityname : '未知城市';
     return $areaName ? $areaName : '未知城市';
 }
Example #3
0
 /**
  * Login user and store user informations in session
  * @param  string $login User login
  * @param  string $pass User password
  * @param  string $mode authorization method email/login
  * @param  string $role webmaster/administrator/admin
  * @return boolean
  */
 function loginUser($login, $password, $mode = "email", $role = "webmaster")
 {
     if (empty($login)) {
         return false;
     }
     $users = new UserModel();
     $c = new Criteria();
     if ($mode == "login") {
         $c->add("login", $login);
     } else {
         $c->add("email", $login);
     }
     $c->add("password", $password);
     $c->add("role", $role);
     $c->add("active", "1");
     $row = $users->find($c);
     if (!empty($row)) {
         foreach ($row as $key => $value) {
             $this->set($key, $value);
         }
         if (empty($row['login'])) {
             $this->set("login", $row['email']);
         }
         return true;
     }
     return false;
 }
Example #4
0
function pageController()
{
    $errors = [];
    if (!Auth::isLoggedIn()) {
        header('Location: users.create.php');
        exit;
    }
    $userObject = UserModel::find($_SESSION['user_id']);
    if (!empty($_POST)) {
        try {
            $userObject->first_name = Input::getString('firstName');
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        try {
            $userObject->last_name = Input::getString('lastName');
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
        if (Input::get('password1') == Input::get('password2')) {
            try {
                $userObject->password = Input::getPassword('password1', $userObject->first_name, $userObject->last_name, $userObject->email);
            } catch (Exception $e) {
                $errors[] = $e->getMessage();
            }
        }
        $userObject->save();
    }
    return ['user' => $userObject, 'errors' => $errors];
}
Example #5
0
 function update()
 {
     $userModel = new UserModel();
     $goods_info = $userModel->find("id={$_GET['id']}");
     print_r($goods_info);
     $test = '用户修改表单';
     $this->display('UserEdit.php', array("goods_info" => $goods_info, "test" => $test));
 }
Example #6
0
 public function getUName()
 {
     $uid = $this->uid ? $this->uid : 0;
     $userName = '';
     if ($uid) {
         $userModel = UserModel::find($uid);
         $userName = $userModel ? $userModel->username : '';
     }
     return $userName ? $userName : '******';
 }
Example #7
0
function pageController()
{
    //initializes the session variable if none exists otherwise it resets it
    //a user id was passed to this page to display
    if (!empty($_GET['id'])) {
        $userID = $_GET['id'];
        $userObject = UserModel::find($userID);
        $userAds = $userObject->getAds();
    }
    return array('userObject' => $userObject, 'userAds' => $userAds);
}
Example #8
0
 /**
  * 获取当前登录用户信息
  */
 protected function user()
 {
     // 获取当前登录用户 Uid
     $uid = Session::get('uid');
     if (!$uid) {
         return null;
     }
     // 获取当前登录用户信息
     $user = UserModel::find($uid);
     return $user ? $user[0] : null;
 }
function user_model_test($delete)
{
    $user = new UserModel("Not", "Here", "*****@*****.**", "password", date("Y-m-d H:i:s"));
    $user->save();
    $user->print_fields();
    $user->set("failed_login_attempts", 3);
    $user->set("first_name", "User");
    $user->set("last_name", "McUsage");
    $user->save();
    $user->print_fields();
    if ($delete) {
        $user->delete();
    }
    $um = UserModel::find(UserModel::first()->id);
    $um->print_fields();
    $um = UserModel::find(UserModel::last()->id);
    $um->print_fields();
    UserModel::find(999);
}
 /**
  * Updates the user data
  *
  * @global type $STRINGS
  * @param type $params
  */
 public function profile_update($params)
 {
     global $STRINGS;
     $userid = array_shift($params);
     //remove url params
     $params = array_slice($params, 1);
     //check if the password is set
     if (empty($params['password'])) {
         //no password is provided -> remove key
         unset($params['password']);
     } else {
         //compute new password and store
         $params['password'] = sha1($params['password']);
     }
     $success = UserModel::update($userid, $params);
     $success == true ? $alert = BootstrapHelper::alert('success', $STRINGS['event:success'], $STRINGS['user:update:success']) : ($alert = BootstrapHelper::alert('error', $STRINGS['event:error'], $STRINGS['user:update:failed']));
     //refresh the user data
     $this->_data->user = UserModel::find($userid);
     new UserProfileView($this->_data, $alert);
 }
 public function testDeleteAll()
 {
     $userTable = new UserModel();
     $letterTable = new LetterListModel();
     $userTable->deleteAll();
     $letter = $letterTable->find();
     $user = $userTable->find();
     $this->assertTrue($letter == null && $user == null);
 }
 private function compute_intervals($params)
 {
     if (isset($params[0]) && !empty($params[0])) {
         //a user is specified
         $users = array('user' => UserModel::find($params[0]));
     } else {
         //all users
         $users = UserModel::find_all();
     }
     if ($users) {
         foreach ($users as $user) {
             //get activity without incidences
             $activity = ActivityModel::find_all_by_user_not_computed($user->id);
             if ($activity) {
                 $activity_entries = array();
                 //group 2 by 2
                 $grouped_activities = null;
                 for ($i = 0; $i < count($activity); $i = $i + 2) {
                     //group only when we have both members
                     if ($activity[$i] && $activity[$i + 1]) {
                         $grouped_activities[] = array($activity[$i], $activity[$i + 1]);
                         //mark activities as computed
                         $activity_entries[] = $activity[$i]->id;
                         $activity_entries[] = $activity[$i + 1]->id;
                     }
                 }
                 $intervals = null;
                 foreach ($grouped_activities as $gactivity) {
                     //check data integrity
                     if ($gactivity[0]->action == 'checkin' && $gactivity[1]->action == 'checkout') {
                         //compute the interval
                         $date_start = new DateTime(date(DATE_ATOM, $gactivity[0]->timestamp));
                         $date_end = new DateTime(date(DATE_ATOM, $gactivity[1]->timestamp));
                         $date_diff = $date_start->diff($date_end);
                         $interval = new stdClass();
                         $interval->userid = $gactivity[0]->userid;
                         $interval->timestart = $gactivity[0]->timestamp;
                         $interval->timestop = $gactivity[1]->timestamp;
                         $interval->timediff = $gactivity[1]->timestamp - $gactivity[0]->timestamp;
                         $interval->week = date('W', $gactivity[0]->timestamp);
                         $interval->month = date('n', $gactivity[0]->timestamp);
                         $interval->year = date('o', $gactivity[0]->timestamp);
                         $interval->y = $date_diff->y;
                         $interval->m = $date_diff->m;
                         $interval->d = $date_diff->d;
                         $interval->h = $date_diff->h;
                         $interval->i = $date_diff->i;
                         $interval->s = $date_diff->s;
                         $intervals[] = $interval;
                     } else {
                         die(print_r("FATAL: Corrupted database!\n"));
                     }
                 }
                 //save the intervals to the DB
                 if ($intervals) {
                     IntervalModel::create_multiple($intervals);
                 }
                 if ($activity_entries) {
                     ActivityModel::mark_as_computed($activity_entries);
                 }
             }
         }
     }
 }
 /**
  * Tests the update method
  */
 public function testUpdate()
 {
     //update main tester user data
     UserModel::update('999999', array('UUID' => '1x3'));
     $updated_user = UserModel::find('999999');
     //check if the data is updated
     $this->assertEquals($updated_user->UUID, '1x3');
 }
Example #14
0
 public function resetPassword()
 {
     $this->view = new HTMLView();
     if ($this->request->isPOST()) {
         $post = $this->request->postData();
         $user = new UserModel();
         if ($this->request->isQueryArgSet('token')) {
             if ($user->getUserForPasswordResetToken($this->request->queryArgValue('token'))) {
                 $user->password = @$post['password'];
                 if ($user->save()) {
                     $user->deletePasswordResetTokens();
                     $alert = new Alert(Alert::SUCCESS);
                     $alert->addMessage('Password Set, Please Login');
                 } else {
                     $alert = new Alert(Alert::ERROR);
                     $alert->addMessageArray($user->getErrors());
                 }
                 $this->view->includeTemplate('auth.reset-password.password', ['app_name' => AppConfig::getValue('app_name'), 'alert' => $alert]);
             } else {
                 AppController::redirect(RouteController::fqURL('resetPassword'), ['status' => 'token-expired']);
             }
         } else {
             if ($post['email'] && $user->find($post['email'], 'email')) {
                 $token = $user->getPasswordResetTokenData();
                 if ($token['last_email_timestamp'] <= Carbon::now()->subMinutes(pow(2, $token['email_attempts']))) {
                     $user->incrementPasswordResetEmailCount();
                     $link = addQueryParams(RouteController::fqURL('resetPassword'), ['token' => $token['token']]);
                     // Send Email
                     $mailer = new Mailer();
                     $mailer->setSubject('Password Reset Token');
                     $mailer->addAddress($user->email);
                     $mailer->includeHTMLTemplate('email.reset-password', ['link' => $link]);
                     $mailer->send();
                     // errors handled within
                     // Show Message
                     $alert = new Alert(Alert::SUCCESS);
                     $alert->addMessage('Email Sent');
                 } else {
                     $alert = new Alert(Alert::ERROR);
                     $alert->addMessage('Too Many Attempts, Please Try Again Later');
                 }
                 $this->view->includeTemplate('auth.reset-password.email', ['app_name' => AppConfig::getValue('app_name'), 'alert' => $alert]);
             } else {
                 $alert = new Alert(Alert::ERROR);
                 $alert->addMessage('Email is Invalid/Non-Existent');
                 $this->view->includeTemplate('auth.reset-password.email', ['app_name' => AppConfig::getValue('app_name'), 'alert' => $alert]);
             }
         }
     } else {
         if ($this->request->isQueryArgSet('token')) {
             $user = new UserModel();
             if ($user->getUserForPasswordResetToken($this->request->queryArgValue('token'))) {
                 $this->view->includeTemplate('auth.reset-password.password', ['app_name' => AppConfig::getValue('app_name')]);
             } else {
                 AppController::redirect(RouteController::fqURL('resetPassword'), ['status' => 'token-expired']);
             }
         } else {
             if ($this->request->isQueryArgSet('status') && $this->request->queryArgValue('status') == 'token-expired') {
                 $alert = new Alert(Alert::ERROR);
                 $alert->addMessage('Token is Invalid/Expired, Please Request a New One');
             }
             $this->view->includeTemplate('auth.reset-password.email', ['app_name' => AppConfig::getValue('app_name'), 'alert' => isset($alert) ? $alert : null]);
         }
     }
     $this->view->render(true);
 }
 public function finished($user_id, $token)
 {
     if (true === $this->init($user_id, $token)) {
         $this->layout->content = View::make('laravel-quiz::contents.finished')->with('quiz', $this->quiz)->with('result', $this->result);
         $user = \UserModel::find($user_id);
         if ($user) {
             VisitModel::add($user, $this->quiz);
         }
     }
 }
 public function testDeleteAllUser()
 {
     $userTable = new UserModel();
     $moodTable = new MoodListModel();
     $userTable->deleteAll();
     $this->assertTrue($moodTable->find() == NULL && $userTable->find() == NULL);
 }
 public function resource($id)
 {
     $user = UserModel::find($id);
     return View::make('resource')->with('user', $user);
 }
Example #18
0
 /**
  * 确定供应方信息
  */
 public function getSupplyName()
 {
     $userModel = UserModel::find($this->supply);
     return $userModel ? $userModel->username : '******';
 }
 /**
  * Builds a report using the passed parameters, and displays the result
  * using the report show view
  *
  * @param Array $params
  */
 public function report_build($params)
 {
     global $STRINGS;
     $formdata = (object) $params;
     $this->_data->user = UserModel::find($formdata->user);
     $this->_data->range = IntervalModel::get_range_total($formdata);
     $this->_data->intervals = IntervalModel::get_between($formdata);
     $this->_data->incidences = ActivityModel::find_all_incidences($formdata->user);
     //check if the report is not empty
     if (empty($this->_data->range->total) && empty($this->_data->intervals) && empty($this->_data->incidences)) {
         $alert = BootstrapHelper::alert('info', $STRINGS['event:noactivity'], $STRINGS['event:noactivityinterval:message']);
         new AdminReportView(UserModel::find_all(), $alert);
     } else {
         new AdminReportShowView($this->_data);
     }
 }
Example #20
0
<?php

/*主页展示*/
define('ACC', true);
require './include/init.php';
if (!isset($_SESSION['id'])) {
    $nl = false;
} else {
    /*找出用户id*/
    $uid = $_SESSION['id'];
    $user = new UserModel();
    $uinfo = $user->find($uid);
    $nl = true;
}
/*作品展示*/
$word = new WordModel();
$wrs = $word->selectWord(0);
//var_dump($wrs[2]['introduction']);
for ($i = 0; $i < count($wrs); $i++) {
    $wrs[$i]['introduction'] = nl2br($wrs[$i]['introduction']);
    //var_dump($itr);
}
include ROOT . '/templates/main.html';
 public function testDeleteAll()
 {
     $userTable = new UserModel();
     $commentTable = new CommentModel();
     $moodTable = new MoodListModel();
     $userTable->deleteAll();
     $comment = $commentTable->find();
     $mood = $moodTable->find();
     $user = $userTable->find();
     $this->assertTrue($comment == null && $user == null && $mood == null);
 }
 public function testDeleteAllUser()
 {
     $userTable = new UserModel();
     $moodTable = new MoodListModel();
     $praiseTable = new PraiseMoodModel();
     $userTable->deleteAll();
     $user = $userTable->find();
     $mood = $moodTable->find();
     $praise = $praiseTable->find();
     $this->assertTrue($user === null && $mood === null && $praise === null);
 }
Example #23
0
 /**
  * 发布人信息
  */
 public function user()
 {
     $uid = $this->uid ? $this->uid : 0;
     $userModel = UserModel::find($uid);
     return $userModel ? $userModel : '';
 }