an attempt at something
This commit is contained in:
parent
97593040e0
commit
737f6695c2
6 changed files with 55 additions and 39 deletions
|
@ -124,7 +124,7 @@ class AuthController extends Controller
|
|||
return Template::render('global/information');
|
||||
}
|
||||
|
||||
if (strlen($user->password) < 1) {
|
||||
if ($user->passwordExpired()) {
|
||||
$message = 'Your password expired.';
|
||||
$redirect = Router::route('auth.resetpassword');
|
||||
Template::vars(compact('message', 'redirect'));
|
||||
|
@ -132,7 +132,7 @@ class AuthController extends Controller
|
|||
return Template::render('global/information');
|
||||
}
|
||||
|
||||
if (!password_verify($password, $user->password)) {
|
||||
if (!$user->verifyPassword($password)) {
|
||||
$this->touchRateLimit($user->id);
|
||||
$message = 'The password you entered was invalid.';
|
||||
Template::vars(compact('message', 'redirect'));
|
||||
|
@ -552,16 +552,7 @@ class AuthController extends Controller
|
|||
return Template::render('global/information');
|
||||
}
|
||||
|
||||
// Hash the password
|
||||
$password = password_hash($password, PASSWORD_BCRYPT);
|
||||
|
||||
// Update the user
|
||||
DB::table('users')
|
||||
->where('user_id', $user->id)
|
||||
->update([
|
||||
'password' => $password,
|
||||
'password_chan' => time(),
|
||||
]);
|
||||
$user->setPassword($password);
|
||||
|
||||
$message = "Changed your password! You may now log in.";
|
||||
$redirect = Router::route('auth.login');
|
||||
|
|
|
@ -12,6 +12,7 @@ use Sakura\DB;
|
|||
use Sakura\News\Category;
|
||||
use Sakura\Template;
|
||||
use Sakura\User;
|
||||
use Sakura\UserTest;
|
||||
|
||||
/**
|
||||
* Meta page controllers (sections that aren't big enough to warrant a dedicated controller).
|
||||
|
@ -28,6 +29,10 @@ class MetaController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
$test = new UserTest(1);
|
||||
|
||||
echo $test->country(true);
|
||||
|
||||
// Get the newest user
|
||||
$newestUserId = DB::table('users')
|
||||
->whereNotIn('rank_main', [config('rank.banned'), config('rank.inactive')])
|
||||
|
|
|
@ -114,7 +114,7 @@ class AdvancedController extends Controller
|
|||
}
|
||||
|
||||
// Check password
|
||||
if (!password_verify($password, ActiveUser::$user->password)) {
|
||||
if (!ActiveUser::$user->passwordVerify($password)) {
|
||||
$message = "Your password was invalid!";
|
||||
Template::vars(compact('redirect', 'message'));
|
||||
return Template::render('global/information');
|
||||
|
|
|
@ -36,15 +36,15 @@ class Notification
|
|||
if ($data) {
|
||||
$data = $data[0];
|
||||
|
||||
$this->id = $data->alert_id;
|
||||
$this->user = $data->user_id;
|
||||
$this->time = $data->alert_timestamp;
|
||||
$this->id = intval($data->alert_id);
|
||||
$this->user = intval($data->user_id);
|
||||
$this->time = intval($data->alert_timestamp);
|
||||
$this->read = intval($data->alert_read) !== 0;
|
||||
$this->title = $data->alert_title;
|
||||
$this->text = $data->alert_text;
|
||||
$this->link = $data->alert_link;
|
||||
$this->image = $data->alert_img;
|
||||
$this->timeout = $data->alert_timeout;
|
||||
$this->timeout = intval($data->alert_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
45
app/User.php
45
app/User.php
|
@ -45,28 +45,7 @@ class User
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public $passwordHash = '';
|
||||
|
||||
/**
|
||||
* The user's password salt.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $passwordSalt = '';
|
||||
|
||||
/**
|
||||
* The user's password algorithm.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $passwordAlgo = 'disabled';
|
||||
|
||||
/**
|
||||
* The password iterations.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $passwordIter = 0;
|
||||
public $password = '';
|
||||
|
||||
/**
|
||||
* UNIX timestamp of last time the password was changed.
|
||||
|
@ -1119,6 +1098,28 @@ class User
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if password expired
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function passwordExpired()
|
||||
{
|
||||
return strlen($this->password) < 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the user's password
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verifyPassword($password)
|
||||
{
|
||||
return password_verify($password, $this->password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the notifications for this user.
|
||||
*
|
||||
|
|
19
utility.php
19
utility.php
|
@ -41,6 +41,25 @@ function view($name, $vars = [])
|
|||
return Template::render($name);
|
||||
}
|
||||
|
||||
// Convert camel case to snake case
|
||||
function camel_to_snake($text)
|
||||
{
|
||||
return ltrim(strtolower(preg_replace('#[A-Z]#', '_$0', $text)), '_');
|
||||
}
|
||||
|
||||
// Convert snake case to camel case
|
||||
function snake_to_camel($text)
|
||||
{
|
||||
$split = explode('_', $text);
|
||||
$name = array_shift($split);
|
||||
|
||||
foreach ($split as $part) {
|
||||
$name .= ucfirst($part);
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
function clean_string($string, $lower = false, $noSpecial = false, $replaceSpecial = '')
|
||||
{
|
||||
// Run common sanitisation function over string
|
||||
|
|
Reference in a new issue