mirror of
https://github.com/fazo96/homework.git
synced 2025-01-10 12:14:22 +01:00
added login safety and animation
This commit is contained in:
parent
9d94fa0532
commit
8de8f3739e
24
app.coffee
24
app.coffee
@ -1,22 +1,31 @@
|
|||||||
notes = new Meteor.Collection "notes"
|
notes = new Meteor.Collection "notes"
|
||||||
|
|
||||||
|
# Server
|
||||||
if Meteor.isServer
|
if Meteor.isServer
|
||||||
Accounts.config {
|
Accounts.config {
|
||||||
sendVerificationEmail: true
|
sendVerificationEmail: false
|
||||||
loginExpirationInDays: 1
|
loginExpirationInDays: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Meteor.publish "my-notes", ->
|
Meteor.publish "my-notes", ->
|
||||||
notes.find( { userId: @userId } ) unless not @userId
|
notes.find( { userId: @userId } ) unless not @userId
|
||||||
|
|
||||||
if Meteor.isClient
|
# Authentication
|
||||||
|
Accounts.validateNewUser (user) ->
|
||||||
|
if user.email and Meteor.check(user.email,String) is yes and user.email.contains '@' is yes and user.email.endsWith '.' is no and user.email.endsWith '@' is no
|
||||||
|
return yes
|
||||||
|
else throw new Meteor.Error 403, "Invalid Email"
|
||||||
|
if user.password and Meteor.check(user.password,String) is yes and user.password.length > 7
|
||||||
|
return yes
|
||||||
|
else throw new Meteor.Error 403, "Password invalid"
|
||||||
|
|
||||||
Meteor.subscribe "my-notes"
|
# Client
|
||||||
|
if Meteor.isClient
|
||||||
|
Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId()
|
||||||
|
|
||||||
# User Interface
|
# User Interface
|
||||||
Template.userInfo.events {
|
Template.userInfo.events {
|
||||||
'click #logout': (e,template) ->
|
'click #logout': (e,template) -> Meteor.logout()
|
||||||
Meteor.logout()
|
|
||||||
'keypress #newNote': (e,template) ->
|
'keypress #newNote': (e,template) ->
|
||||||
if e.keyCode is 13
|
if e.keyCode is 13
|
||||||
notes.insert {
|
notes.insert {
|
||||||
@ -79,7 +88,8 @@ if Meteor.isClient
|
|||||||
pressLogin = (template) ->
|
pressLogin = (template) ->
|
||||||
mail = template.find('#mail').value; pass = template.find('#pass').value
|
mail = template.find('#mail').value; pass = template.find('#pass').value
|
||||||
Meteor.loginWithPassword mail, pass, (err) ->
|
Meteor.loginWithPassword mail, pass, (err) ->
|
||||||
errCallback err; if Meteor.userId() then clearNotifications()
|
errCallback err
|
||||||
|
Template.auth.working = -> Meteor.loggingIn()
|
||||||
Template.auth.events {
|
Template.auth.events {
|
||||||
'keypress .login': (e,template) ->
|
'keypress .login': (e,template) ->
|
||||||
if e.keyCode is 13 then pressLogin template
|
if e.keyCode is 13 then pressLogin template
|
||||||
@ -95,7 +105,7 @@ if Meteor.isClient
|
|||||||
Accounts.createUser {
|
Accounts.createUser {
|
||||||
email: mail,
|
email: mail,
|
||||||
password: pass
|
password: pass
|
||||||
}, (e) -> errCallback e; if Meteor.userId() then clearNotifications()
|
}, (e) -> errCallback e
|
||||||
catch err
|
catch err
|
||||||
notify { msg: err }
|
notify { msg: err }
|
||||||
}
|
}
|
||||||
|
20
index.html
20
index.html
@ -35,12 +35,20 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<p>Register a new Account or login</p>
|
<p>Register a new Account or login</p>
|
||||||
{{> notifications }}
|
{{> notifications }}
|
||||||
<input type="text" id="mail" class="form-control login" placeholder="Email">
|
{{#if working}}
|
||||||
<input type="password" id="pass" class="form-control login" placeholder="Password">
|
<div align="center" class="spinning-cog">
|
||||||
<br>
|
<i class="fa fa-cog fa-spin fa-3x"></i>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<input type="text" id="mail" class="form-control login" placeholder="Email">
|
||||||
|
<input type="password" id="pass" class="form-control login" placeholder="Password">
|
||||||
|
<br>
|
||||||
|
{{/if}}
|
||||||
<p>Password must be at least 8 characters. Email must be a valid email</p>
|
<p>Password must be at least 8 characters. Email must be a valid email</p>
|
||||||
<button type="button" id="register" class="btn-auth btn btn-info">Register</button>
|
{{#unless working}}
|
||||||
<button type="button" id="login" class="btn-auth btn btn-info">Login</button>
|
<button type="button" id="register" class="btn-auth btn btn-info">Register</button>
|
||||||
|
<button type="button" id="login" class="btn-auth btn btn-info">Login</button>
|
||||||
|
{{/unless}}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -73,7 +81,7 @@
|
|||||||
|
|
||||||
<template name="notifications">
|
<template name="notifications">
|
||||||
{{#each notification}}
|
{{#each notification}}
|
||||||
<div class="alert alert-{{type}}">
|
<div class="alert alert-{{type}} notification">
|
||||||
<p align="center">{{msg}}</p>
|
<p align="center">{{msg}}</p>
|
||||||
<button type="button" class="close close-notification">×</button>
|
<button type="button" class="close close-notification">×</button>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user