mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 01:32:38 +00:00
Added option to stay logged in permanently
This commit is contained in:
parent
66095738e3
commit
8540fc44f3
@ -25,11 +25,12 @@ class LoginController extends BaseController
|
||||
{
|
||||
$user = $this->Database->users()->where('username', $postParams['username'])->fetch();
|
||||
$inputPassword = $postParams['password'];
|
||||
$stayLoggedInPermanently = $postParams['stay_logged_in'] == 'on';
|
||||
|
||||
if ($user !== null && password_verify($inputPassword, $user->password))
|
||||
{
|
||||
$sessionKey = $this->SessionService->CreateSession($user->id);
|
||||
setcookie($this->SessionCookieName, $sessionKey, time() + 31536000); // Cookie expires in 1 year, but session validity is up to SessionService
|
||||
$sessionKey = $this->SessionService->CreateSession($user->id, $stayLoggedInPermanently);
|
||||
setcookie($this->SessionCookieName, $sessionKey, time() + 31220640000); // Cookie expires in 999 years, but session validity is up to SessionService
|
||||
|
||||
if (password_needs_rehash($user->password, PASSWORD_DEFAULT))
|
||||
{
|
||||
|
@ -241,6 +241,8 @@ return array(
|
||||
'Edit product group' => 'Produktgruppe bearbeiten',
|
||||
'Product group' => 'Produktgruppe',
|
||||
'Are you sure to delete product group "#1"?' => 'Produktgruppe "#1" wirklich löschen?',
|
||||
'Stay logged in permanently' => 'Dauerhaft angemeldet bleiben',
|
||||
'When not set, you will get logged out at latest after 30 days' => 'Wenn nicht gesetzt, wirst du spätestens nach 30 Tagen automatisch abgemeldet',
|
||||
|
||||
//Constants
|
||||
'manually' => 'Manuell',
|
||||
|
@ -33,14 +33,20 @@ class SessionService extends BaseService
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function CreateSession($userId)
|
||||
public function CreateSession($userId, $stayLoggedInPermanently = false)
|
||||
{
|
||||
$newSessionKey = $this->GenerateSessionKey();
|
||||
|
||||
$expires = date('Y-m-d H:i:s', time() + 2592000); // Default is that sessions expire in 30 days
|
||||
if ($stayLoggedInPermanently === true)
|
||||
{
|
||||
$expires = date('Y-m-d H:i:s', time() + 31220640000); // 999 years aka forever
|
||||
}
|
||||
|
||||
$sessionRow = $this->Database->sessions()->createRow(array(
|
||||
'user_id' => $userId,
|
||||
'session_key' => $newSessionKey,
|
||||
'expires' => date('Y-m-d H:i:s', time() + 2592000) // Default is that sessions expire in 30 days
|
||||
'expires' => $expires
|
||||
));
|
||||
$sessionRow->save();
|
||||
|
||||
|
@ -22,6 +22,13 @@
|
||||
<div id="login-error" class="form-text text-danger d-none"></div>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
<label for="stay_logged_in">
|
||||
<input type="checkbox" id="stay_logged_in" name="stay_logged_in"> {{ $L('Stay logged in permanently') }}
|
||||
<p id="qu-conversion-info" class="form-text text-muted small my-0">{{ $L('When not set, you will get logged out at latest after 30 days') }}</p>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<button id="login-button" type="submit" class="btn btn-success">{{ $L('OK') }}</button>
|
||||
|
||||
</form>
|
||||
|
Loading…
x
Reference in New Issue
Block a user