1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
var SignupView = FormView.extend({
el: "#signup",
action: sdk.account.signup,
last_data: null,
/*
test_data: {
"Email": "testit.account" + Math.floor(Math.random() * 10000000) + "@yoox.com",
"Password": "TestPassword",
"Password2": "TestPassword",
"Gender": "U",
"Name": "TestName",
"Surname": "TestSurname",
"BirthDay": "1978-11-12",
"DataProfiling": true,
},
*/
events: {
"click .privacy-msg": "privacy_link",
"submit form": "save",
},
initialize: function(){
this.$form = this.$(".form")
this.$msg = this.$(".msg")
this.scroller = new IScroll('#signup', app.iscroll_options)
},
show: function(){
if (auth.logged_in()) {
app.router.go("intro")
return
}
var msg = "* Your personal and payment<br>information will always remain private"
app.footer.show("SUBMIT")
this.$("input").val("")
this.$msg.html(msg)
document.body.className = "signup"
this.preload()
this.deferScrollToTop()
},
validate_presence: {
"Name": "Please enter your first name.",
"Surname": "Please enter your last name.",
"Email": "Please enter a valid email address.",
"ConfirmEmail": "Please enter a valid email address.",
"BirthDay": "Please enter your birthday. You must be 18 or older to use the Stone Island app.",
"Password": "Please enter your password.",
"Password2": "Please enter your password again.",
"DataProfiling": "You must consent to data profiling to use the Stone Island app.",
"AccountTerms": "You must agree to the Your My Account terms.",
},
validate_fields: function(data, errors){
console.log(data)
if (data.Password.length < 7) { errors.push([ "Password", "Password must be 7 characters or more." ]) }
if (data.Password !== data.Password2) { errors.push([ "Password2", "Passwords don't match." ]) }
if (! data.Email.match("@")) { errors.push([ "Email", "Email address is not valid." ]) }
if (data.Email.toLowerCase() !== data.ConfirmEmail.toLowerCase()) { errors.push([ "ConfirmEmail", "Email addresses don't match." ]) }
// if (data.Gender === "NONE") { errors.push([ "Gender", "Please supply your gender." ]) }
if (data.DataProfiling !== "true") { errors.push([ "DataProfiling", "You must consent to data profiling to use the Stone Island app." ]) }
if (data.AccountTerms !== "true") { errors.push([ "AccountTerms", "You must agree to the Your My Account terms to use the Stone Island app." ]) }
var now = new Date ()
var year = now.getFullYear()
if (! data.Birthday) data.BirthDay = year + '-01-01'
if (data.BirthDay.split('-')[0] || '2018')
var birthday = new Date (data.BirthDay)
if (isNaN(birthday) || (now - birthday) / (365*24*60*60*1000) < 18) {
errors.push(['BirthDay', 'You must be 18 or older to use the Stone Island app.'])
}
data.YooxLetter = this.$("[name=YooxLetter]").prop("checked")
},
finalize: function(data){
delete data.ConfirmEmail
data.Gender = "U"
data.BirthDay += "T00:00:00Z"
this.last_data = data
console.log(data)
return data
},
privacy_link: function(){
// rewrite app.privacy instance temporarily
app.privacy.back = function(){
app.router.go("account/signup")
}
app.privacy.hide = function(){
app.privacy.back = app.privacy.hide = null
}
app.router.go("page/privacy")
},
success: function(data){
console.log('success', data)
auth.user = auth.user || {}
auth.user.Name = this.last_data.Name
auth.user.Surname = this.last_data.Surname
auth.user.Email = this.last_data.Email
auth.user.BirthDay = this.last_data.BirthDay
localStorage.setItem('account_terms.consent', 'true')
app.account.logged_in(function(){ app.router.go("store") })
},
error: function(data){
try {
data = JSON.parse(data.responseText)
app.signup.show_errors([[ 'Name', data['Error']['Description'] ]])
}
catch (e) {
switch (data.status) {
case 409:
app.signup.show_errors([[ 'Email', "Email is already in use." ]])
break
default:
app.signup.show_errors([[ 'Name', "There was an unknown error." ]])
break
}
}
},
cancel: function(){
auth.deferred_product = null
},
})
|