summaryrefslogtreecommitdiff
path: root/includes/pages/user_settings.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-10-11 01:26:34 +0200
committermsquare <msquare@notrademark.de>2018-10-31 13:43:23 +0100
commit4e09ee3eb255160c88a378375d69123a3e000497 (patch)
treee4a03ff40c939473cc1278f8286675cfa31e4556 /includes/pages/user_settings.php
parent7c6afc2bfe3263b91ecabf5530da57fe1162ea0b (diff)
Replaced more user related stuff
(Contains some buggy stuff too...)
Diffstat (limited to 'includes/pages/user_settings.php')
-rw-r--r--includes/pages/user_settings.php91
1 files changed, 31 insertions, 60 deletions
diff --git a/includes/pages/user_settings.php b/includes/pages/user_settings.php
index cf8d2f0b..fbcd8baf 100644
--- a/includes/pages/user_settings.php
+++ b/includes/pages/user_settings.php
@@ -1,7 +1,7 @@
<?php
use Carbon\Carbon;
-use Engelsystem\Database\DB;
+use Engelsystem\Models\User\User;
/**
* @return string
@@ -14,10 +14,10 @@ function settings_title()
/**
* Change user main attributes (name, dates, etc.)
*
- * @param array $user_source The user
+ * @param User $user_source The user
* @param bool $enable_tshirt_size
* @param array $tshirt_sizes
- * @return array
+ * @return User
*/
function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
{
@@ -26,7 +26,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('mail')) {
$result = User_validate_mail($request->input('mail'));
- $user_source['email'] = $result->getValue();
+ $user_source->email = $result->getValue();
if (!$result->isValid()) {
$valid = false;
error(__('E-mail address is not correct.'));
@@ -36,20 +36,11 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
error(__('Please enter your e-mail.'));
}
- $user_source['email_shiftinfo'] = $request->has('email_shiftinfo');
- $user_source['email_by_human_allowed'] = $request->has('email_by_human_allowed');
-
- if ($request->has('jabber')) {
- $result = User_validate_jabber($request->input('jabber'));
- $user_source['jabber'] = $result->getValue();
- if (!$result->isValid()) {
- $valid = false;
- error(__('Please check your jabber account information.'));
- }
- }
+ $user_source->settings->email_shiftinfo = $request->has('email_shiftinfo');
+ $user_source->settings->email_human = $request->has('email_by_human_allowed');
if ($request->has('tshirt_size') && isset($tshirt_sizes[$request->input('tshirt_size')])) {
- $user_source['Size'] = $request->input('tshirt_size');
+ $user_source->personalData->shirt_size = $request->input('tshirt_size');
} elseif ($enable_tshirt_size) {
$valid = false;
}
@@ -57,7 +48,7 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('planned_arrival_date')) {
$tmp = parse_date('Y-m-d H:i', $request->input('planned_arrival_date') . ' 00:00');
$result = User_validate_planned_arrival_date($tmp);
- $user_source['planned_arrival_date'] = $result->getValue();
+ $user_source->personalData->planned_arrival_date = Carbon::createFromTimestamp($result->getValue());
if (!$result->isValid()) {
$valid = false;
error(__('Please enter your planned date of arrival. It should be after the buildup start date and before teardown end date.'));
@@ -66,8 +57,8 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
if ($request->has('planned_departure_date')) {
$tmp = parse_date('Y-m-d H:i', $request->input('planned_departure_date') . ' 00:00');
- $result = User_validate_planned_departure_date($user_source['planned_arrival_date'], $tmp);
- $user_source['planned_departure_date'] = $result->getValue();
+ $result = User_validate_planned_departure_date($user_source->personalData->arrival_date->getTimestamp(), $tmp);
+ $user_source->personalData->planned_departure_date = Carbon::createFromTimestamp($result->getValue());
if (!$result->isValid()) {
$valid = false;
error(__('Please enter your planned date of departure. It should be after your planned arrival date and after buildup start date and before teardown end date.'));
@@ -75,21 +66,21 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
}
// Trivia
- $user_source['Name'] = strip_request_item('lastname', $user_source['Name']);
- $user_source['Vorname'] = strip_request_item('prename', $user_source['Vorname']);
- $user_source['Alter'] = strip_request_item('age', $user_source['Alter']);
- $user_source['Telefon'] = strip_request_item('tel', $user_source['Telefon']);
+ $user_source->name = strip_request_item('lastname', $user_source['Name']);
+ $user_source->personalData->first_name = strip_request_item('prename', $user_source['Vorname']);
if (strlen(strip_request_item('dect')) <= 5) {
- $user_source['DECT'] = strip_request_item('dect', $user_source['DECT']);
+ $user_source->contact->dect = strip_request_item('dect', $user_source['DECT']);
} else {
$valid = false;
error(__('For dect numbers are only 5 digits allowed.'));
}
- $user_source['Handy'] = strip_request_item('mobile', $user_source['Handy']);
- $user_source['Hometown'] = strip_request_item('hometown', $user_source['Hometown']);
+ $user_source->contact->mobile = strip_request_item('mobile', $user_source['Handy']);
if ($valid) {
- User_update($user_source);
+ $user_source->save();
+ $user_source->contact->save();
+ $user_source->personalData->save();
+ $user_source->settings->save();
success(__('Settings saved.'));
redirect(page_link_to('user_settings'));
@@ -101,14 +92,14 @@ function user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes)
/**
* Change user password.
*
- * @param array $user_source The user
+ * @param User $user_source The user
*/
function user_settings_password($user_source)
{
$request = request();
if (
!$request->has('password')
- || !verify_password($request->postData('password'), $user_source['Passwort'], $user_source['UID'])
+ || !verify_password($request->postData('password'), $user_source->password, $user_source->id)
) {
error(__('-> not OK. Please try again.'));
} elseif (strlen($request->postData('new_password')) < config('min_password_length')) {
@@ -116,7 +107,7 @@ function user_settings_password($user_source)
} elseif ($request->postData('new_password') != $request->postData('new_password2')) {
error(__('Your passwords don\'t match.'));
} else {
- set_password($user_source['UID'], $request->postData('new_password'));
+ set_password($user_source->id, $request->postData('new_password'));
success(__('Password saved.'));
}
redirect(page_link_to('user_settings'));
@@ -125,9 +116,9 @@ function user_settings_password($user_source)
/**
* Change user theme
*
- * @param array $user_source The user
+ * @param User $user_source The user
* @param array $themes List of available themes
- * @return array
+ * @return User
*/
function user_settings_theme($user_source, $themes)
{
@@ -135,22 +126,13 @@ function user_settings_theme($user_source, $themes)
$request = request();
if ($request->has('theme') && isset($themes[$request->input('theme')])) {
- $user_source['color'] = $request->input('theme');
+ $user_source->settings->theme = $request->input('theme');
} else {
$valid = false;
}
if ($valid) {
- DB::update('
- UPDATE `User`
- SET `color`=?
- WHERE `UID`=?
- ',
- [
- $user_source['color'],
- $user_source['UID'],
- ]
- );
+ $user_source->settings->save();
success(__('Theme changed.'));
redirect(page_link_to('user_settings'));
@@ -162,9 +144,9 @@ function user_settings_theme($user_source, $themes)
/**
* Change use locale
*
- * @param array $user_source The user
+ * @param User $user_source The user
* @param array $locales List of available locales
- * @return array
+ * @return User
*/
function user_settings_locale($user_source, $locales)
{
@@ -173,23 +155,14 @@ function user_settings_locale($user_source, $locales)
$session = session();
if ($request->has('language') && isset($locales[$request->input('language')])) {
- $user_source['Sprache'] = $request->input('language');
+ $user_source->settings->language = $request->input('language');
} else {
$valid = false;
}
if ($valid) {
- DB::update('
- UPDATE `User`
- SET `Sprache`=?
- WHERE `UID`=?
- ',
- [
- $user_source['Sprache'],
- $user_source['UID'],
- ]
- );
- $session->set('locale', $user_source['Sprache']);
+ $user_source->settings->save();
+ $session->set('locale', $user_source->settings->language);
success('Language changed.');
redirect(page_link_to('user_settings'));
@@ -205,7 +178,6 @@ function user_settings_locale($user_source, $locales)
*/
function user_settings()
{
- global $user;
$request = request();
$config = config();
$themes = config('available_themes');
@@ -227,8 +199,7 @@ function user_settings()
$teardown_end_date = $teardown->getTimestamp();
}
- $user_source = $user;
-
+ $user_source = auth()->user();
if ($request->has('submit')) {
$user_source = user_settings_main($user_source, $enable_tshirt_size, $tshirt_sizes);
} elseif ($request->has('submit_password')) {