1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-12 21:22:28 +01:00
polr/app/Helpers/UserHelper.php

74 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Helpers;
use App\Models\User;
use Hash;
class UserHelper {
public static function userExists($username) {
$user = User::where('active', 1)
->where('username', $username)
->first();
return ($user ? true : false);
}
public static function emailExists($email) {
$user = User::where('active', 1)
->where('email', $email)
->first();
return ($user ? true : false);
}
public static function validateUsername($username) {
return ctype_alnum($username);
}
public static function validateEmail($email) {
// TODO validate email here
return true;
}
public static function checkCredentials($username, $password) {
$user = User::where('active', 1)
->where('username', $username)
->first();
if ($user == null) {
return false;
}
$correct_password = Hash::check($password, $user->password);
if (!$correct_password) {
return false;
}
else {
return ['username' => $username, 'role' => $user->role];
}
}
2015-11-09 01:49:45 +01:00
public static function createNewRecoveryKey($username) {
$recovery_key = CryptoHelper::generateRandomHex(50);
$user = User::where('active', 1)
->where('username', $username)
->first();
2015-11-09 01:49:45 +01:00
if ($user == null) {
return false;
}
$user->recovery_key = $recovery_key;
$user->save();
}
public static function getUserById($user_id) {
$user = User::where('id', $user_id)
->where('active', 1)
->first();
return $user;
}
}