Add email for users

This commit is contained in:
Kurt Riddlesperger 2020-04-04 16:52:22 -05:00
parent 6f4769a7b3
commit da2d2db4fe
6 changed files with 34 additions and 4 deletions

View File

@ -74,6 +74,14 @@ Setting('DISABLE_BROWSER_BARCODE_CAMERA_SCANNING', false);
# Needs to be a number where Sunday = 0, Monday = 1 and so forth
Setting('MEAL_PLAN_FIRST_DAY_OF_WEEK', '');
# Email smtp settings
Setting('EMAIL_HOST','smtp.gmail.com');
Setting('EMAIL_PORT','587');
Setting('EMAIL_USERNAME','');
Setting('EMAIL_PASSWORD','');
Setting('EMAIL_FROM','from@example.com, from who');
Setting('EMAIL_REPLYTO','noreply@example.com, No Reply');
# Default user settings
# These settings can be changed per user, here the defaults

View File

@ -32,7 +32,7 @@ class UsersApiController extends BaseApiController
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
$this->getUsersService()->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
$this->getUsersService()->CreateUser($requestBody['username'], $requestBody['email'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->EmptyApiResponse($response);
}
catch (\Exception $ex)
@ -60,7 +60,7 @@ class UsersApiController extends BaseApiController
try
{
$this->getUsersService()->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
$this->getUsersService()->EditUser($args['userId'], $requestBody['username'], $requestBody['email'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->EmptyApiResponse($response);
}
catch (\Exception $ex)

View File

@ -40,3 +40,13 @@ JOIN stock s
WHERE pr.parent_product_id != pr.sub_product_id
GROUP BY pr.sub_product_id
HAVING SUM(s.amount) > 0;
ALTER TABLE users
ADD email TEXT;
CREATE TABLE password_reset_temp (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
email TEXT NOT NULL UNIQUE,
key TEXT,
expiration_date DATETIME NOT NULL
);

View File

@ -4,10 +4,11 @@ namespace Grocy\Services;
class UsersService extends BaseService
{
public function CreateUser(string $username, string $firstName, string $lastName, string $password)
public function CreateUser(string $username, string $email, string $firstName, string $lastName, string $password)
{
$newUserRow = $this->getDatabase()->users()->createRow(array(
'username' => $username,
'email' => $email,
'first_name' => $firstName,
'last_name' => $lastName,
'password' => password_hash($password, PASSWORD_DEFAULT)
@ -15,7 +16,7 @@ class UsersService extends BaseService
$newUserRow->save();
}
public function EditUser(int $userId, string $username, string $firstName, string $lastName, string $password)
public function EditUser(int $userId, string $username, string $email, string $firstName, string $lastName, string $password)
{
if (!$this->UserExists($userId))
{
@ -25,6 +26,7 @@ class UsersService extends BaseService
$user = $this->getDatabase()->users($userId);
$user->update(array(
'username' => $username,
'email' => $email,
'first_name' => $firstName,
'last_name' => $lastName,
'password' => password_hash($password, PASSWORD_DEFAULT)

View File

@ -27,6 +27,12 @@
<div class="invalid-feedback">{{ $__t('A username is required') }}</div>
</div>
<div class="form-group">
<label for="email">{{ $__t('Email') }}</label>
<input type="text" class="form-control" required id="email" name="email" value="@if($mode == 'edit'){{ $user->email }}@endif">
<div class="invalid-feedback">{{ $__t('An email is required') }}</div>
</div>
<div class="form-group">
<label for="first_name">{{ $__t('First name') }}</label>
<input type="text" class="form-control" id="first_name" name="first_name" value="@if($mode == 'edit'){{ $user->first_name }}@endif">

View File

@ -30,6 +30,7 @@
<tr>
<th class="border-right"></th>
<th>{{ $__t('Username') }}</th>
<th>{{ $__t('Email') }}</th>
<th>{{ $__t('First name') }}</th>
<th>{{ $__t('Last name') }}</th>
</tr>
@ -48,6 +49,9 @@
<td>
{{ $user->username }}
</td>
<td>
{{ $user->email }}
</td>
<td>
{{ $user->first_name }}
</td>