11import Component from '@ember/component' ;
2+ import { computed } from '@ember/object' ;
23import FormMixin from 'open-event-frontend/mixins/form' ;
34
45export 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+ } ) ,
612
713 getValidationRules ( ) {
814 return {
@@ -23,12 +29,27 @@ export default Component.extend(FormMixin, {
2329 }
2430 ]
2531 } ,
32+
2633 password : {
2734 identifier : 'password' ,
2835 rules : [
2936 {
3037 type : 'empty' ,
3138 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' )
3253 }
3354 ]
3455 }
@@ -37,13 +58,24 @@ export default Component.extend(FormMixin, {
3758 } ,
3859 actions : {
3960 submit ( ) {
40- this . onValid ( ( ) => {
61+ this . onValid ( async ( ) => {
4162 if ( this . userExists ) {
4263 this . loginExistingUser ( this . email , this . password ) ;
64+ } else if ( this . password ) {
65+ this . createNewUserViaEmail ( this . email , this . password ) ;
4366 } 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+ }
4572 }
4673 } ) ;
74+ } ,
75+ reset ( ) {
76+ this . set ( 'userExists' , false ) ;
77+ this . set ( 'showPasswordForm' , false ) ;
78+ this . set ( 'password' , null ) ;
4779 }
4880 }
4981} ) ;
0 commit comments