1
1
import Component from '@ember/component' ;
2
+ import { computed } from '@ember/object' ;
2
3
import FormMixin from 'open-event-frontend/mixins/form' ;
3
4
4
5
export default Component . extend ( FormMixin , {
5
- autoScrollToErrors : false ,
6
+ autoScrollToErrors : false ,
7
+ showPasswordForm : false ,
8
+
9
+ nextStep : computed ( 'userExists' , 'showPasswordForm' , function ( ) {
10
+ return this . userExists || this . showPasswordForm ;
11
+ } ) ,
6
12
7
13
getValidationRules ( ) {
8
14
return {
@@ -23,12 +29,27 @@ export default Component.extend(FormMixin, {
23
29
}
24
30
]
25
31
} ,
32
+
26
33
password : {
27
34
identifier : 'password' ,
28
35
rules : [
29
36
{
30
37
type : 'empty' ,
31
38
prompt : this . l10n . t ( 'Please enter your password' )
39
+ } ,
40
+ {
41
+ type : 'minLength[8]' ,
42
+ prompt : this . l10n . t ( 'Your password must have at least {ruleValue} characters' )
43
+ }
44
+ ]
45
+ } ,
46
+
47
+ passwordRepeat : {
48
+ identifier : 'password_repeat' ,
49
+ rules : [
50
+ {
51
+ type : 'match[password]' ,
52
+ prompt : this . l10n . t ( 'Passwords do not match' )
32
53
}
33
54
]
34
55
}
@@ -37,13 +58,24 @@ export default Component.extend(FormMixin, {
37
58
} ,
38
59
actions : {
39
60
submit ( ) {
40
- this . onValid ( ( ) => {
61
+ this . onValid ( async ( ) => {
41
62
if ( this . userExists ) {
42
63
this . loginExistingUser ( this . email , this . password ) ;
64
+ } else if ( this . password ) {
65
+ this . createNewUserViaEmail ( this . email , this . password ) ;
43
66
} else {
44
- this . createNewUserViaEmail ( this . email ) ;
67
+ const result = await this . loader . post ( 'users/check_email' , { email : this . email } ) ;
68
+ this . set ( 'userExists' , result . exists ) ;
69
+ if ( ! result . exists ) {
70
+ this . set ( 'showPasswordForm' , true ) ;
71
+ }
45
72
}
46
73
} ) ;
74
+ } ,
75
+ reset ( ) {
76
+ this . set ( 'userExists' , false ) ;
77
+ this . set ( 'showPasswordForm' , false ) ;
78
+ this . set ( 'password' , null ) ;
47
79
}
48
80
}
49
81
} ) ;
0 commit comments