Skip to content

Commit

Permalink
Sign-in and Sign-up with Polymer en form-event
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierPT committed Mar 5, 2015
1 parent 0800cc3 commit cd8a97e
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 85 deletions.
1 change: 0 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ iron:router
differential:vulcanize
coffeescript
meteorhacks:subs-manager
useraccounts:polymer
boxxa:polymer
boxxa:polymer-elements
msavin:mongol
6 changes: 1 addition & 5 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ iron:url@1.0.7
jquery@1.11.3
json@1.0.2
launch-screen@1.0.1
less@1.0.12
livedata@1.0.12
localstorage@1.0.2
logging@1.0.6
Expand All @@ -51,7 +50,7 @@ minimongo@1.0.6
mobile-status-bar@1.0.2
mongo@1.0.11
mongo-livedata@1.0.7
msavin:mongol@0.5.4
msavin:mongol@0.5.5
npm-bcrypt@0.7.7
observe-sequence@1.0.4
ordered-dict@1.0.2
Expand All @@ -64,7 +63,6 @@ routepolicy@1.0.4
service-configuration@1.0.3
session@1.0.5
sha@1.0.2
softwarerero:accounts-t9n@1.0.6
spacebars@1.0.5
spacebars-compiler@1.0.4
srp@1.0.2
Expand All @@ -74,7 +72,5 @@ tracker@1.0.5
ui@1.0.5
underscore@1.0.2
url@1.0.3
useraccounts:core@1.8.1
useraccounts:polymer@1.8.1
webapp@1.1.6
webapp-hashing@1.0.2
8 changes: 8 additions & 0 deletions client/stylesheets/teamwork.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ a {
padding: 20px;
}

.single-form {
background-color: white !important;
color: black;
width: 30%;
top:15px;
padding: 20px;
}

.form-team::shadow .content {
background-color: #E0F2F1 !important;
color: black;
Expand Down
6 changes: 6 additions & 0 deletions client/views/material_profile/material_profile.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template name="MaterialProfile">
<div class="content">
<h2>Edit your profile {{username}}</h2>
<event-form-container class="single-form" style="width: 50%; top:15px; alignment-baseline: middle">
<event-form objectId="{{_id}}" eventSuffix="user">
<paper-input-decorator label="User's email" error="The email should be a the good format"
floatingLabel>
Expand All @@ -16,5 +17,10 @@ <h2>Edit your profile {{username}}</h2>
</paper-input-decorator>

</event-form>
<event-paper-button affirmative eventName="save-profile" id="sign-in-btn">
<core-icon icon="check"></core-icon>
Save
</event-paper-button>
</event-form-container>
</div>
</template>
2 changes: 1 addition & 1 deletion client/views/polymer_layout/polymer_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
</div>
{{#if currentUser}}
<paper-item>
<a href="/sign-in">
<a href="/sign-out">
<core-icon icon="exit-to-app"></core-icon>Sign out</a>
</paper-item>
{{/if}}
Expand Down
38 changes: 22 additions & 16 deletions client/views/sign_in/sign_in.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
<template name="SignIn">
<div style="width: 100%;" layout horizontal center center-justified >
<form data-action="sign-in">
<paper-input-decorator label="Username" error="We need a valid username!"
floatingLabel class="input-light">
<input is="core-input" id="username" type="text" required>
</paper-input-decorator>
<div class="content" layout horizontal center-justified>
<paper-shadow z="1" class="single-form">
<div>
<h2>Sign in Teamwork</h2>
<event-form-container>
<event-form>
<paper-input-decorator label="Username" error="We need a valid username!"
floatingLabel class="input-light">
<input is="core-input" name="username" id="username" type="text" required>
</paper-input-decorator>

<paper-input-decorator label="Password" error="Whats your password?"
floatingLabel class="input-light">
<input is="core-input" id="password" type="password" required>
</paper-input-decorator>
<paper-input-decorator label="Password" error="Whats your password?"
floatingLabel class="input-light">
<input is="core-input" name="password" id="password" type="password" required>
</paper-input-decorator>
</event-form>

<div horizontal layout reverse>
<paper-button id="sign-in-btn" type="submit">
<core-icon icon="check"></core-icon>
Sign In
</paper-button>
<event-paper-button affirmative eventName="sign-in" id="sign-in-btn">
<core-icon icon="check"></core-icon>
Sign In
</event-paper-button>

</event-form-container>
</div>
</form>
</paper-shadow>
</div>
</template>
29 changes: 15 additions & 14 deletions client/views/sign_in/sign_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
/* SignIn: Event Handlers and Helpersss .js*/
/*****************************************************************************/
Template.SignIn.events({

'click #sign-in-btn': function (e, tmpl) {
var email = $("#username").val();
var password = $("#password").val();

Meteor.loginWithPassword(email, password, function (error) {
if (error) {
Notification.emitError("Impossible login.", error);
} else {
Router.go("/home");
}
});
}
});

Template.SignIn.helpers({
Expand All @@ -39,7 +26,21 @@ Template.SignIn.rendered = function () {
$("#sign-in-btn").click();
}
})
})
});


// Selector for updating an activty
document.querySelector('.content').addEventListener('sign-in', function (e) {
console.log(e.type, e.detail.objectId);

Meteor.loginWithPassword(e.detail.datas.username, e.detail.datas.password, function (error) {
if (error) {
Notification.emitError("Impossible login.", error);
} else {
Router.go("/home");
}
});
});
};

Template.SignIn.destroyed = function () {
Expand Down
53 changes: 29 additions & 24 deletions client/views/sign_up/sign_up.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
<template name="SignUp">
<div style="width: 100%;" layout horizontal center center-justified >
<form data-action="sign-up">
<paper-input-decorator label="Username" error="We need a username"
floatingLabel class="input-light">
<input is="core-input" id="username" type="text" required>
</paper-input-decorator>
<div class="content" layout horizontal center-justified>
<paper-shadow z="1" class="single-form">
<div>
<h2>Sign up for Teamwork</h2>
<event-form-container>
<event-form>
<paper-input-decorator label="Username" error="We need a username"
floatingLabel class="input-light">
<input is="core-input" name="username" id="username" type="text" required>
</paper-input-decorator>

<paper-input-decorator label="Email Address" error="We need a valid email!"
floatingLabel class="input-light">
<input is="core-input" id="email" type="email" required>
</paper-input-decorator>
<paper-input-decorator label="Email Address" error="We need a valid email!"
floatingLabel class="input-light">
<input is="core-input" name="email" id="email" type="email" required>
</paper-input-decorator>

<paper-input-decorator label="Password" error="Whats your password?"
floatingLabel class="input-light">
<input is="core-input" id="password" type="password" required>
</paper-input-decorator>
<paper-input-decorator label="Password" error="Whats your password?"
floatingLabel class="input-light">
<input is="core-input" name="password" id="password" type="password" required>
</paper-input-decorator>

<paper-input-decorator label="Confirm password" error="Whats your password?"
floatingLabel class="input-light">
<input is="core-input" id="password2" type="password" required>
</paper-input-decorator>
<paper-input-decorator label="Confirm password" error="Whats your password?"
floatingLabel class="input-light">
<input is="core-input" name="password2" id="password2" type="password" required>
</paper-input-decorator>
</event-form>

<div horizontal layout reverse>
<paper-button id="sign-up-btn">
<core-icon icon="check"></core-icon>
Sign Up
</paper-button>
<event-paper-button affirmative eventName="sign-up" id="sign-up-btn">
<core-icon icon="check"></core-icon>
Sign Up
</event-paper-button>
</event-form-container>
</div>
</form>
</paper-shadow>
</div>
</template>
56 changes: 32 additions & 24 deletions client/views/sign_up/sign_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,7 @@
/* SignUp: Event Handlers and Helpersss .js*/
/*****************************************************************************/
Template.SignUp.events({
'click #sign-up-btn': function (e, tmpl) {
var username = $("#username").val();
var email = $("#email").val();
var password = $("#password").val();
var password2 = $("#password2").val();

check(username, NonEmptyString);
check(email, NonEmptyString);
check(password, NonEmptyString);
check(password2, NonEmptyString);
if (password != password2) {
throw new Meteor.Error("sign-up", "The password is not verified.");
}


Accounts.createUser(username, email, password, function (error) {
if (error) {
Notification.emitError("Impossible to create user.", error);
} else {
Router.go("/home");
}
});
}

});

Template.SignUp.helpers({
Expand All @@ -49,7 +27,37 @@ Template.SignUp.rendered = function () {
$("#sign-up-btn").click();
}
})
})
});

// Selector for updating an activty
document.querySelector('.content').addEventListener('sign-up', function (e) {
console.log(e.type, e.detail.objectId);

var options = {};
options.username = e.detail.datas.username;
options.email = e.detail.datas.email;
var password = e.detail.datas.password;
var password2 = e.detail.datas.password2;

check(options.username, NonEmptyString);
check(options.email, NonEmptyString);
check(password, NonEmptyString);
check(password2, NonEmptyString);
if (password != password2) {
throw new Meteor.Error("sign-up", "The password is not verified.");
}
options.password = password;

Accounts.createUser(options, function (error) {
if (error) {
Notification.emitError("Impossible to create user.", error);
} else {
Router.go("/home");
}
});
});


};
Template.SignUp.destroyed = function () {
};

0 comments on commit cd8a97e

Please sign in to comment.