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


PHP User::getUserByUsername方法代碼示例

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


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

示例1: function

 $app->post('/login', function () use($app) {
     // check for required params
     $toVerify = array('username', 'password');
     R::verifyRequiredParams($toVerify);
     $app->add(new \Slim\Middleware\ContentTypes());
     $response = array();
     $code = 500;
     $body = $app->request()->getBody();
     $request = json_decode($body, true);
     $username = $request['username'];
     $password = $request['password'];
     $oUser = new User();
     // check for correct email and password
     if ($oUser->checkLogin($username, $password)) {
         // get the user by username
         $user = $oUser->getUserByUsername($username);
         if ($user != NULL) {
             $loginId = $user['LoginID'];
             $response['error'] = false;
             $response['login_id'] = $user['LoginID'];
             $response['username'] = $user['username'];
             $response['group_id'] = $user['GroupID'];
             $response['locale'] = $user['locale'];
             $public_key = $oUser->generateKeys($loginId, $username, $password);
             // field in DB is NULL by default, so let's check if they have been already created before.
             if ($public_key != NULL) {
                 $response['public_key'] = $public_key;
                 $code = 200;
             } else {
                 $response['public_key'] = "could not create or read keys";
                 $code = 500;
開發者ID:Rudianasaja,項目名稱:openMEDIS-Slim-PHP-REST-API,代碼行數:31,代碼來源:user.router.php

示例2: header

<?php

/**
 * Created by PhpStorm.
 * User: Kondziu
 * Date: 2016-02-06
 * Time: 15:30
 */
require_once '/../models/user.php';
use models\User;
$user = $request->get('login');
$password = $request->get('password');
$user = User::getUserByUsername($user);
if (isset($user)) {
    if (password_verify($password, $user->password)) {
        $_SESSION['user'] = $user->login;
        $_SESSION['admin'] = $user->admin;
        $_SESSION['loggedIn'] = true;
        header('Location: ' . str_replace('/login', '/', $request->getUri()));
    } else {
        $_SESSION['loggedIn'] = false;
        header('Location: ' . str_replace('/login', '/', $request->getUri()));
    }
}
die;
開發者ID:kRojecki,項目名稱:DelegationSystem,代碼行數:25,代碼來源:login.php


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