Update registration form

2022-03-24
Luca 3 years ago
parent 633e36b5f3
commit 08d6f8e3e5

@ -258,9 +258,6 @@ return [
// Whether the DECT field should be enabled
'enable_dect' => (bool)env('ENABLE_DECT', false),
// Enables prename and lastname
'enable_user_name' => (bool)env('ENABLE_USER_NAME', true),
// Enable displaying the pronoun fields
'enable_pronoun' => (bool)env('ENABLE_PRONOUN', false),
@ -270,12 +267,12 @@ return [
// Enables the T-Shirt configuration on signup and profile
'enable_tshirt_size' => (bool)env('ENABLE_TSHIRT_SIZE', false),
// Enables the goody/voucher configuration on signup and profile
'enable_goody' => (bool)env('ENABLE_GOODY', false),
// Enables shifts export as iCal/JSON (if disabled, buttons/links will not be shown, but endpoints will still work)
'enable_shifts_export' => (bool)env('ENABLE_SHIFTS_EXPORT', false),
// Enables joining angel types on registration
'enable_angeltype_signup' => (bool)env('ENABLE_ANGELTYPE_SIGNUP', false),
// Number of shifts to freeload until angel is locked for shift signup.
'max_freeloadable_shifts' => env('MAX_FREELOADABLE_SHIFTS', 1),

@ -28,29 +28,24 @@ function guest_register()
$authUser = auth()->user();
$tshirt_sizes = config('tshirt_sizes');
$enable_tshirt_size = config('enable_tshirt_size');
$enable_user_name = config('enable_user_name');
$enable_dect = config('enable_dect');
$enable_planned_arrival = config('enable_planned_arrival');
$min_password_length = config('min_password_length');
$enable_password = config('enable_password');
$enable_pronoun = config('enable_pronoun');
$enable_angeltype_signup = config('enable_angeltype_signup');
$config = config();
$request = request();
$session = session();
$is_oauth = $session->has('oauth2_connect_provider');
$msg = '';
$nick = '';
$lastName = '';
$preName = '';
$dect = '';
$mobile = '';
$email = '';
$pronoun = '';
$email_shiftinfo = false;
$email_by_human_allowed = false;
$email_news = false;
$email_goody = false;
$mobile_consent = false;
$tshirt_size = '';
$password_hash = '';
$selected_angel_types = [];
@ -97,53 +92,37 @@ function guest_register()
if ($request->hasPostData('submit')) {
$valid = true;
if ($request->has('username')) {
$nickValidation = User_validate_Nick($request->input('username'));
$nick = $nickValidation->getValue();
if (!$nickValidation->isValid()) {
$valid = false;
$msg .= error(sprintf(__('Please enter a valid nick.') . ' ' . __('Use up to 24 letters, numbers, connecting punctuations or spaces for your nickname.'),
$nick), true);
}
if (User::whereName($nick)->count() > 0) {
$valid = false;
$msg .= error(sprintf(__('Your nick "%s" already exists.'), $nick), true);
}
if ($request->has('prename')) {
$preName = strip_request_item('prename');
} else {
$valid = false;
$msg .= error(__('Please enter a nickname.'), true);
$msg .= error(__('Please enter your first name.'), true);
}
if ($request->has('email') && strlen(strip_request_item('email')) > 0) {
$email = strip_request_item('email');
if (!check_email($email)) {
$valid = false;
$msg .= error(__('E-mail address is not correct.'), true);
}
if (User::whereEmail($email)->first()) {
$valid = false;
$msg .= error(__('E-mail address is already used by another user.'), true);
}
if ($request->has('lastname')) {
$lastName = strip_request_item('lastname');
} else {
$valid = false;
$msg .= error(__('Please enter your e-mail.'), true);
}
if ($request->has('email_shiftinfo')) {
$email_shiftinfo = true;
$msg .= error(__('Please enter your last name.'), true);
}
if ($request->has('email_by_human_allowed')) {
$email_by_human_allowed = true;
}
if ($request->has('mobile')) {
$mobile = strip_request_item('mobile');
if ($request->has('email_news')) {
$email_news = true;
if (User::whereName($mobile)->count() > 0) {
$valid = false;
$msg .= error(__('This mobile number is already in use.'), true);
}
} else {
$valid = false;
$msg .= error(__('Please enter your mobile number.'), true);
}
if ($request->has('email_goody')) {
$email_goody = true;
if ($request->has('mobile_consent')) {
$mobile_consent = true;
} else {
$valid = false;
$msg .= error(__('Please consent to receiving notifications via SMS.'), true);
}
if ($enable_tshirt_size) {
@ -189,12 +168,6 @@ function guest_register()
}
// Trivia
if ($enable_user_name && $request->has('lastname')) {
$lastName = strip_request_item('lastname');
}
if ($enable_user_name && $request->has('prename')) {
$preName = strip_request_item('prename');
}
if ($enable_pronoun && $request->has('pronoun')) {
$pronoun = strip_request_item('pronoun');
}
@ -206,15 +179,12 @@ function guest_register()
error(__('For dect numbers are only 40 digits allowed.'));
}
}
if ($request->has('mobile')) {
$mobile = strip_request_item('mobile');
}
if ($valid) {
$user = new User([
'name' => $nick,
'name' => $mobile,
'password' => $password_hash,
'email' => $email,
'email' => $mobile,
'api_key' => '',
'last_login_at' => null,
]);
@ -242,10 +212,10 @@ function guest_register()
$settings = new Settings([
'language' => $session->get('locale'),
'theme' => config('theme'),
'email_human' => $email_by_human_allowed,
'email_goody' => $email_goody,
'email_shiftinfo' => $email_shiftinfo,
'email_news' => $email_news,
'email_human' => $mobile_consent,
'email_goody' => $mobile_consent,
'email_shiftinfo' => $mobile_consent,
'email_news' => $mobile_consent,
]);
$settings->user()
->associate($user)
@ -336,14 +306,6 @@ function guest_register()
$form_data = $session->get('form_data');
$session->remove('form_data');
if (!$nick && !empty($form_data['name'])) {
$nick = $form_data['name'];
}
if (!$email && !empty($form_data['email'])) {
$email = $form_data['email'];
}
if (!$preName && !empty($form_data['first_name'])) {
$preName = $form_data['first_name'];
}
@ -360,79 +322,39 @@ function guest_register()
form([
div('row', [
div('col', [
form_text(
'username',
__('Nick') . ' ' . entry_required(),
$nick,
false,
24,
'nickname'
),
form_info('',
__('Use up to 24 letters, numbers, connecting punctuations or spaces for your nickname.'))
form_text('prename', __('First name') . ' ' . entry_required(), $preName, false, 64, 'given-name')
]),
div('col', [
form_text('lastname', __('Last name') . ' ' . entry_required(), $lastName, false, 64, 'family-name')
])
$enable_pronoun ? div('col', [
form_text('pronoun', __('Pronoun'), $pronoun, false, 15)
]) : '',
]),
$enable_user_name ? div('row', [
div('col', [
form_text('prename', __('First name'), $preName, false, 64, 'given-name')
]),
div('col', [
form_text('lastname', __('Last name'), $lastName, false, 64, 'family-name')
])
]) : '',
div('row', [
div('col', [
form_email(
'email',
__('E-Mail') . ' ' . entry_required(),
$email,
form_text(
'mobile',
__('Mobile'),
$mobile,
false,
'email',
254
),
form_checkbox(
'email_shiftinfo',
__(
'The %s is allowed to send me an email (e.g. when my shifts change)',
[config('app_name')]
),
$email_shiftinfo
),
form_checkbox(
'email_news',
__('Notify me of new news'),
$email_news
40,
'tel-national'
),
form_checkbox(
'email_by_human_allowed',
__('Allow heaven angels to contact you by e-mail.'),
$email_by_human_allowed
'mobile_consent',
__('I consent to receive notifications via SMS.') . ' ' . entry_required(),
$mobile_consent
),
config('enable_goody') ?
form_checkbox(
'email_goody',
__('To receive vouchers, give consent that nick, email address, worked hours and shirt size will be stored until the next similar event.')
. (config('privacy_email') ? ' ' . __('To withdraw your approval, send an email to <a href="mailto:%s">%1$s</a>.', [config('privacy_email')]) : ''),
$email_goody
) : '',
]),
$enable_dect ? div('col', [
form_text('dect', __('DECT'), $dect, false, 40, 'tel-local')
]) : '',
div('col', [
form_text('mobile', __('Mobile'), $mobile, false, 40, 'tel-national')
])
]),
div('row', [
$enable_password || $enable_planned_arrival ? div('row', [
$enable_password ? div('col', [
form_password('password', __('Password') . ' ' . entry_required())
]) : '',
@ -444,21 +366,22 @@ function guest_register()
$planned_arrival_date, $buildup_start_date, $teardown_end_date
)
]) : '',
]),
]) : '',
div('row', [
$enable_password || $enable_tshirt_size ? div('row', [
$enable_password ? div('col', [
form_password('password2', __('Confirm password') . ' ' . entry_required())
]) : '',
div('col', [
$enable_tshirt_size ? form_select('tshirt_size',
$enable_tshirt_size ? div('col', [
form_select('tshirt_size',
__('Shirt size') . ' ' . entry_required(),
$tshirt_sizes, $tshirt_size, __('Please select...')) : ''
]),
]),
$tshirt_sizes, $tshirt_size, __('Please select...')
)
]) : '',
]) : '',
div('row', [
$enable_angeltype_signup ? div('row', [
div('col', [
form_checkboxes(
'angel_types',
@ -475,7 +398,7 @@ function guest_register()
__('Some angel types have to be confirmed later by a supporter at an introduction meeting. You can change your selection in the options section.')
)
])
]),
]) : '',
form_submit('submit', __('Register'))
])

Loading…
Cancel
Save