Example #1
0
/**
 * User Login
 * url - /login
 * method - POST
 * params - email, password
 */
$app->post('/login', function () use($app) {
    // check for required params
    verifyRequiredParams(array('email', 'password'));
    // reading post params
    $email = $app->request()->post('email');
    $password = $app->request()->post('password');
    $response = array();
    $db = new DbHandler();
    // check for correct email and password
    $user = $db->checkLogin($email, $password);
    if (is_array($user)) {
        // get the user by email
        //$user = $db->getUserByEmail($email);
        /*    sage_roles.user_id,
              sage_roles.user_login,
              sage_roles.access_level,
              sage_roles.when_last_login*/
        if ($user != NULL) {
            $response["error"] = false;
            $response['user_id'] = $user['user_id'];
            $_SESSION['user_id'] = $user['user_id'];
            $response['email'] = $user['user_login'];
            $response['access_level'] = $user['access_level'];
            $response['when_last_login'] = $user['when_last_login'];
        } else {
Example #2
0
/**
 * User Login
 * url - /login
 * method - POST
 * params - email, password
 */
$app->post('/login', function () use($app) {
    // check for required params
    verifyRequiredParams(array('email', 'password'));
    // reading post params
    $email = $app->request()->post('email');
    $password = $app->request()->post('password');
    $response = array();
    $db = new DbHandler();
    // check for correct email and password
    if ($db->checkLogin($email, $password)) {
        // get the user by email
        $user = $db->getUserByEmail($email);
        if ($user != NULL) {
            $response["error"] = false;
            $response['name'] = $user['name'];
            $response['email'] = $user['email'];
            $response['apiKey'] = $user['api_key'];
            $response['created_at'] = $user['created_at'];
        } else {
            // unknown error occurred
            $response['error'] = true;
            $response['message'] = "An error occurred. Please try again";
        }
    } else {
        // user credentials are wrong
Example #3
0
                $user_id = $user["UserID"];
            }
        }
    } else {
        // api key is missing in header
        $response["error"] = true;
        $response["message"] = "Api key is misssing";
        echoRespnse(400, $response);
        $app->stop();
    }
}
$app->post('/login', function () use($app) {
    $body = $app->request->getBody();
    $data = json_decode($body, true);
    $db = new DbHandler();
    $loginResult = $db->checkLogin($data["username"], $data["password"]);
    if ($loginResult) {
        $user = $db->getUserByUserID($loginResult);
        $userRoleResult = $db->getUserRolesByUserID($loginResult);
        $userRoles = array();
        while ($userRole = $userRoleResult->fetch_assoc()) {
            array_push($userRoles, $userRole["Name"]);
        }
        // $userCompetitionsResult = $db->getUserCompetitionsByUserID($loginResult);
        $userCompetitions = array();
        // while ($userCompetition = $userCompetitionsResult->fetch_assoc()) {
        //   array_push($userCompetitions, $userCompetition);
        // }
        $response = createToken($user, $userRoles, $userCompetitions);
        echo $response;
    } else {
Example #4
0
/**
 * Descrição
 * @param $usuario
 *  {
 *      'login':'******',
 *      'senha':'valor'
 *  }
 * 
 * @return $usuario HTTP-202
 *  {
 *      codigo: 21,
 *      login: "******",
 *      nome:"João Silva",
 *      tipoUsuario: "1",
 *      ativo: TRUE | FALSE,
 *  }
 * @return $erro HTTP-400
 */
function verificarLogin()
{
    $request = \Slim\Slim::getInstance()->request();
    $body = $request->getBody();
    $usuarioJson = json_decode($body);
    $login = $usuarioJson->login;
    $senha = $usuarioJson->senha;
    // Validação do dados de entrada para o login do usuário.
    $validacao = LoginValidate::validate($login, $senha);
    if ($validacao == VALIDO) {
        $db = new DbHandler();
        $autorizado = $db->checkLogin($login, $senha);
        if ($autorizado) {
            // Recuperar usuário pelo login (e-mail).
            $usuario = $db->getUsuarioByLogin($login);
            // Dados do usuário.
            echoRespnse(HTTP_ACEITO, $usuario);
        } else {
            // Usuário não encontrado e não autorizado.
            $erro = MapaErro::singleton()->getErro(2);
            echoRespnse(NAO_AUTORIZADO, $erro);
        }
    } else {
        $erro = MapaErro::singleton()->getErro($validacao);
        echoRespnse(HTTP_REQUISICAO_INVALIDA, $erro);
    }
}
Example #5
0
            }
        }
    }
    // echo json response
    echoRespnse(201, $response);
});
$app->post('/login', function () use($app) {
    // check for required params
    verifyRequiredParams(array('login', 'password'));
    // reading post params
    $login = $app->request()->post('login');
    $password = $app->request()->post('password');
    $response = array();
    $db = new DbHandler();
    // check for correct email and password
    if ($db->checkLogin($login, $password)) {
        $response["error"] = false;
        $response['user_key'] = $db->getUserKey($login);
    } else {
        // user credentials are wrong
        $response['error'] = true;
        $response['message'] = 'Login failed. Incorrect credentials';
    }
    echoRespnse(200, $response);
});
$app->get('/check_player', 'authenticate', function () {
    global $user_id;
    $response = array();
    $db = new DbHandler();
    $result = $db->checkIsSetup($user_id);
    $response["exist"] = $result;
Example #6
0
//GET login route
$app->get('/login', function () use($app) {
    $app->render('login.php');
});
//POST login route
$app->post('/login', function () use($app) {
    //create empty response array
    $response = array();
    //read post params
    $email_username = $app->request->post('username');
    $password = $app->request->post('password');
    //instantiate the DbHandler class and call the checkloging method
    require_once './classes/DbHandler.php';
    $db = new DbHandler();
    //check for correct email and password combination
    if ($db->checkLogin($email_username, $password)) {
        //valid user - get user details
        $user = $db->getUserByEmail($email_username);
        if (!empty($user)) {
            //          var_dump($user);
            foreach ($user as $item) {
                $userid = $item['user_id'];
                $firstName = $item['first_name'];
                $lastName = $item['last_name'];
                $username = $item['user_name'];
                $fullname = $firstName . ' ' . $lastName;
                $admin = $item['admin'];
                $expired = $item['notexpired'];
            }
            //store data in session
            $_SESSION['user_id'] = $userid;
Example #7
0
        // User with same email already existed in the db
        $response["status"] = "-11";
        $response["message"] = "PROFILE_NOT_EXIST";
        // return $response;
    }
    jsonResponse(200, $response);
});
$app->post('/login', 'authenticate', function () use($app) {
    verifyRequiredParams(array('userName', 'password'));
    // reading post params
    $userName = $app->request()->post('userName');
    $password = $app->request()->post('password');
    $response = array();
    $db = new DbHandler();
    // check for correct email and password
    if ($db->checkLogin($userName, $password)) {
        // get the user by email
        $profileMaster = new profile_master();
        $profileMaster = $profileMaster->getOneByAny(array(user_name => $userName, email_id => $userName, mobile_number => $userName), NULL, NULL);
        if ($profileMaster != NULL) {
            $rndmString = generateRandomString();
            $tokenString = encodeAuthToken($profileMaster->getProfileId(), $rndmString);
            $profileLoginAuth = new profile_login_auth();
            $profileLoginAuth->setUserName($profileMaster->getUserName());
            $profileLoginAuth->setProfileId($profileMaster->getProfileId());
            $profileLoginAuth->setLoginTime(time());
            $profileLoginAuth->setLoginClientIp(get_client_ip());
            $profileLoginAuth->setLoginSecretKey($rndmString);
            $profileLoginAuth->setLoginAuthToken($tokenString);
            $profileLoginAuth->setLastOpuser('admin');
            $profileLoginAuth->save();