Skip to content

Commit f01ee52

Browse files
committed
Home页添加登陆功能(UGLY,从 account.js 拷贝了不少代码)
1 parent 1aa0763 commit f01ee52

File tree

1 file changed

+59
-16
lines changed

1 file changed

+59
-16
lines changed

home/index.html

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ <h1>Protoshop</h1>
2727
<span class="fa fa-angle-right"></span>
2828
<div class="show-mobile"><span class="fa fa-mobile"></span><br />View on Mobile</div>
2929
</div>
30-
<form class="login-form">
30+
<form id="login-form" class="login-form">
3131
<ul>
32-
<li><input type="text" placeholder="Email Address" required /></li>
33-
<li><input type="text" placeholder="Nickname" required /></li>
34-
<li><input type="password" placeholder="Password" required /></li>
35-
<li><button class="btn-login">Sign Up</button><a href="../app/" class="link-form">Login</a></li>
32+
<li><input name="email" type="text" placeholder="Email Address" required /></li>
33+
<li><input name="nick" type="text" placeholder="Nickname" required /></li>
34+
<li><input name="pass" type="password" placeholder="Password" required /></li>
35+
<li><button class="btn-login">Sign Up</button><a id="login" href="../app/" class="link-form">Login</a></li>
3636
</ul>
3737
</form>
3838
</div>
@@ -130,10 +130,32 @@ <h3><em>View</em>On Mobile<span class="qrcode-download"></span></h3>
130130
<i class="fa fa-coffee"></i> <a href="https://qr.alipay.com/ap27zqsxo3v5q61z1f" title="求咖灰~~~" target="_blank">Buy me a coffee!</a><span class="qrcode-donate"></span> (੭ु๑‾᷄ ⁻̫ ‾᷅)੭ु⁾⁾
131131
</div>
132132
</div>
133-
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
133+
<script src="../app/bower_components/jquery/jquery.js"></script>
134+
<script src="../app/scripts/libs/md5.js"></script>
134135
<script>
135136
$(function(){
136-
137+
138+
// ENVIRONMENT
139+
var env;
140+
if (/debug|localhost/.test(window.location.href)) {
141+
env = 'debug';
142+
} else if (/ctripqa/.test(window.location.href)) {
143+
env = 'ctqa';
144+
} else {
145+
env = 'open';
146+
}
147+
148+
var apiHosts = {
149+
debug: 'http://10.2.254.48/debugProtoShop/',
150+
ctqa: 'http://10.2.254.48/ProtoShop/',
151+
open: 'http://api.protoshop.io/'
152+
};
153+
154+
var ENV = {
155+
env: env,
156+
apiHost: apiHosts[env]
157+
};
158+
137159
// Scroll Func
138160
$('nav span').on('click',function($e){
139161
scrollTo('#splash');
@@ -159,15 +181,36 @@ <h3><em>View</em>On Mobile<span class="qrcode-download"></span></h3>
159181
}
160182

161183
// Body Class
162-
var env = 'unknown';
163-
if (/debug|localhost/.test(window.location.href)) {
164-
env = 'debug';
165-
} else if (/ctripqa/.test(window.location.href)) {
166-
env = 'ctqa';
167-
} else {
168-
env = 'open';
169-
}
170-
$('body').addClass('env-' + env);
184+
$('body').addClass('env-' + ENV.env);
185+
186+
// Register
187+
$('#login-form').on('submit', function (e) {
188+
var form = e.target;
189+
190+
// 将密码做 MD5 转换
191+
var data = {
192+
email: form.email.value,
193+
passwd: V.Security.md5(form.pass.value),
194+
nickname: form.nick.value
195+
};
196+
197+
// 注册
198+
$.post(ENV.apiHost + 'register/', data)
199+
.success(function (res) {
200+
switch (res.status) {
201+
case 0:
202+
var loggedInUser = res.result[0];
203+
localStorage.setItem('loggedInUser', JSON.stringify(loggedInUser));
204+
window.location.href = $('#login').attr('href');
205+
break;
206+
default:
207+
console.log('Registration Error.');
208+
}
209+
});
210+
211+
e.preventDefault();
212+
});
213+
171214
});
172215
</script>
173216
</body>

0 commit comments

Comments
 (0)