當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::authenticate方法代碼示例

本文整理匯總了PHP中User::authenticate方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::authenticate方法的具體用法?PHP User::authenticate怎麽用?PHP User::authenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在User的用法示例。


在下文中一共展示了User::authenticate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 /**
  * To check if username is valid and existing
  * To check if username and password matched
  * Validation to proceed to Thread page
  **/
 public function index()
 {
     $username = Param::get('login_name');
     $password = Param::get('login_pword');
     $user = new User();
     $login_info = array('username' => $username, 'password' => $password);
     if (!array_filter($login_info)) {
         $status = "";
     } else {
         try {
             foreach ($login_info as $key => $value) {
                 if (!is_complete($value)) {
                     throw new ValidationException("Please fill up all fields");
                 }
             }
             $user_login = $user->authenticate($username, $password);
             $_SESSION['username'] = $user_login->username;
             redirect(url('thread/index'));
         } catch (ValidationException $e) {
             $status = notice($e->getMessage(), "error");
         } catch (RecordNotFoundException $e) {
             $status = notice($e->getMessage(), "error");
         }
     }
     $this->set(get_defined_vars());
 }
開發者ID:LowellaMercurio,項目名稱:board-1,代碼行數:31,代碼來源:user_controller.php

示例2: authenticate

 /**
  * Disable BackendUser authentication redirect and cache the result
  */
 public function authenticate()
 {
     if ($this->frontendHelperUserAuthenticated === null) {
         $this->frontendHelperUserAuthenticated = \User::authenticate();
     }
     return $this->frontendHelperUserAuthenticated;
 }
開發者ID:madeyourday,項目名稱:contao-rocksolid-frontend-helper,代碼行數:10,代碼來源:FrontendHelperUser.php

示例3: set_current_user

 protected function set_current_user()
 {
     $user = null;
     $AnonymousUser = array('id' => 0, 'level' => 0, 'name' => "Anonymous", 'show_samples' => true, 'language' => '', 'secondary_languages' => '', 'pool_browse_mode' => 1, 'always_resize_images' => true, 'ip_addr' => $this->request()->remoteIp());
     if (!current_user() && $this->session()->user_id) {
         $user = User::where(['id' => $this->session()->user_id])->first();
     } else {
         if ($this->cookies()->login && $this->cookies()->pass_hash) {
             $user = User::authenticate_hash($this->cookies()->login, $this->cookies()->pass_hash);
         } elseif (isset($this->params()->login) && isset($this->params()->password_hash)) {
             $user = User::authenticate($this->params()->login, $this->params()->password_hash);
         } elseif (isset($this->params()->user['name']) && isset($this->params()->user['password'])) {
             $user = User::authenticate($this->params()->user['name'], $this->params()->user['password']);
         }
         $user && $user->updateAttribute('last_logged_in_at', date('Y-m-d H:i:s'));
     }
     if ($user) {
         if ($user->is_blocked() && $user->ban && $user->ban->expires_at < date('Y-m-d H:i:s')) {
             $user->updateAttribute('level', CONFIG()->starting_level);
             Ban::destroyAll("user_id = " . $user->id);
         }
         $this->session()->user_id = $user->id;
     } else {
         $user = new User();
         $user->assignAttributes($AnonymousUser, ['without_protection' => true]);
     }
     User::set_current_user($user);
     $this->current_user = $user;
     # For convenient access in activerecord models
     $user->ip_addr = $this->request()->remoteIp();
     Moebooru\Versioning\Versioning::init_history();
     if (!current_user()->is_anonymous()) {
         current_user()->log($this->request()->remoteIp());
     }
 }
開發者ID:JCQS04,項目名稱:myimouto,代碼行數:35,代碼來源:ApplicationController.php

示例4: login

 function login($request)
 {
     $templateArr = array();
     $modelClass = 'User';
     $formData = array();
     if ($request->user->is_authenticated()) {
         HttpResponseRedirect(pjango_ini_get('LOGIN_REDIRECT_URL'));
     }
     if ($request->POST) {
         $form = new Pjango\Contrib\Auth\Forms\LoginForm($request->POST);
         try {
             if (!$form->is_valid()) {
                 throw new Exception(pjango_gettext('There are some errors, please correct them below.'));
             }
             $formData = $form->cleaned_data();
             $user = User::authenticate($formData['username'], $formData['password']);
             HttpResponseRedirect(pjango_ini_get('LOGIN_REDIRECT_URL'));
         } catch (Exception $e) {
             Messages::Error($e->getMessage());
         }
     }
     if (!$form) {
         $form = new Pjango\Contrib\Auth\Forms\LoginForm($formData);
     }
     $templateArr['addchange_form'] = $form->as_list();
     render_to_response('auth/login.html', $templateArr);
 }
開發者ID:hbasria,項目名稱:pjango,代碼行數:27,代碼來源:Views.php

示例5: postLogin

 public function postLogin()
 {
     $email = Input::get('email');
     $password = Input::get('password');
     if (User::authenticate(['email' => $email, 'password' => $password], Input::has('rememberme'))) {
         return Redirect::intended('/admin');
     }
     return Redirect::to('/login')->withInput()->withErrors('Такой связки email и пароля нет.');
 }
開發者ID:OlesKashchenko,項目名稱:SkillsProject2,代碼行數:9,代碼來源:BackendAdminController.php

示例6: create

 public function create($username, $password)
 {
     $user = User::authenticate($username, $password);
     if ($user === false) {
         Redirect('session/create?error=yes');
     }
     $_SESSION['user'] = $user;
     Redirect('index.php');
 }
開發者ID:natureday1,項目名稱:Life,代碼行數:9,代碼來源:session.php

示例7: store

 public static function store()
 {
     $user = User::authenticate($_POST['username'], $_POST['password']);
     if ($user) {
         $_SESSION['user'] = $user->id;
         Redirect::to("/task", array('message' => "Welcome back."));
     }
     View::make('session/new.html', array('errors' => array("Wrong password or username.")));
 }
開發者ID:tuureilmarinen,項目名稱:tsoha,代碼行數:9,代碼來源:session_controller.php

示例8: register

function register($info = null)
{
    $session = mySession::getInstance();
    if ($session->isLoggedIn()) {
        $session->logout();
    }
    if ($info !== null) {
        //check email and username they have to be unique
        $check = User::getUserByCred($info->email, $info->username);
        if (!$check) {
            $temp_user = new User();
            $temp_user->username = $info->username;
            $temp_user->email = $info->email;
            $temp_user->password = sha1($info->password);
            $temp_user->first_name = $info->first;
            $temp_user->last_name = $info->last;
            $temp_user->gender = $info->gender;
            $temp_user->rights = 'normal';
            $temp_user->status = 'current';
            $temp_user->valid = 1;
            $temp_user->save();
            $found_user = User::authenticate($temp_user->username, $temp_user->password);
            if ($found_user) {
                // log them in
                $session->login($found_user);
                // grab the account status
                $profile_status = $found_user->status;
                if ($profile_status != 'current') {
                    // their account isn't set up so log them out send them to the login page.
                    $session->logout();
                    $session->message("Creating your user profile failed");
                    return false;
                } else {
                    // send verification email.
                    $to = $found_user->email;
                    $check = substr($found_user->password, -12);
                    $subject = "familyhistorydatabase.org verification email";
                    $message = "You are now registered at familyhistorydatabase.org.\n";
                    $message = $message . "\nTo verify your membership click on the link below.\nIf you weren't requesting membership, please ignore this email, and we send our appologies!";
                    $message = $message . "\n" . APIURL . "user/validate/?id=" . $found_user->id . "&validate={$check}";
                    $from = "noreply@familyhistorydatabase.org";
                    $headers = "From:" . $from;
                    mail($to, $subject, $message, $headers);
                    unset($found_user->password);
                    return $found_user;
                }
            }
        } else {
            // If User Not Found
            return false;
        }
    } else {
        // If User Not Found
        return false;
    }
    exit;
}
開發者ID:Jonathan-Law,項目名稱:fhd,代碼行數:57,代碼來源:user.php

示例9: login

 public static function login($parameters)
 {
     $id = User::authenticate($parameters);
     if ($id != null) {
         $content["success"] = "Login was succesful";
     } else {
         $content["error"] = "Login failed. Username/password combination was invalid.";
     }
     return $content;
 }
開發者ID:hyttijan,項目名稱:MyImgur,代碼行數:10,代碼來源:UserController.php

示例10: login

 public static function login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if ($user) {
         $_SESSION['user'] = $user->id;
         Redirect::to(\Slim\Slim::getInstance()->urlFor('index'), array('message' => 'Olet kirjautunut sisään'));
     } else {
         Redirect::to(\Slim\Slim::getInstance()->urlFor('login'), array('message' => 'Kirjautuminen epäonnistui', 'error' => true));
     }
 }
開發者ID:laazz,項目名稱:talpa,代碼行數:11,代碼來源:user_controller.php

示例11: handle_login

 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Invalid username or password!', 'username' => $params['username']));
     } else {
         $_SESSION['user'] = $user->id;
     }
     Redirect::to('/', array('message' => 'Login successful!'));
 }
開發者ID:banjohirvi,項目名稱:Tsoha-Bootstrap,代碼行數:11,代碼來源:user_controller.php

示例12: handle_login

 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['kayttajanimi'], $params['salasana']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Väärä käyttäjätunnus tai salasana!', 'kayttajanimi' => $params['kayttajanimi']));
     } else {
         $_SESSION['user'] = $user->kayttaja_id;
         Redirect::to('/', array('message' => 'Tervetuloa takaisin ' . $user->kayttajanimi . '!'));
     }
 }
開發者ID:saranas,項目名稱:Tsoha-Bootstrap,代碼行數:11,代碼來源:user_controller.php

示例13: handle_login

 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         Redirect::to('/user/login', array('errors' => array('Invalid username or password'), 'attr' => $_POST));
     } else {
         $_SESSION['user'] = $user->id;
         Redirect::to('/', array('message' => 'Welcome back ' . $user->name . '!'));
     }
 }
開發者ID:Rochet2,項目名稱:Tsoha-Bootstrap,代碼行數:11,代碼來源:user_controller.php

示例14: run

 public function run($username, $password)
 {
     global $session;
     $userReg = User::authenticate($username, $password);
     if ($userReg) {
         $session->login($userReg);
         return true;
     } else {
         return false;
     }
 }
開發者ID:runningjack,項目名稱:RobertJohnson,代碼行數:11,代碼來源:login_model.php

示例15: handle_login

 public static function handle_login()
 {
     $params = $_POST;
     $user = User::authenticate($params['username'], $params['password']);
     if (!$user) {
         View::make('user/login.html', array('error' => 'Väärä käyttätunnus tai salasana', 'username' => $params['username']));
     } else {
         $_SESSION['user'] = $user->id;
         Redirect::to('/memo', array('message' => 'Tervetuloa takaisin ' . $user->name . '.'));
     }
 }
開發者ID:Hecarrah,項目名稱:Tsoha-Bootstrap,代碼行數:11,代碼來源:userController.php


注:本文中的User::authenticate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。