Skip to content

Commit

Permalink
user signup module method working
Browse files Browse the repository at this point in the history
  • Loading branch information
luiseduardobrito committed Sep 16, 2013
1 parent 03e909d commit 83bf8fb
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 20 deletions.
8 changes: 8 additions & 0 deletions api/controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = {
});
},

signup: function(req, res) {

response(res).view("home/signup", {
title: "node-web-cluster",
destination: req.param("destination") || "dashboard"
});
},

dashboard: function(req, res) {

policy(req, res).check(["logged_in"], function() {
Expand Down
6 changes: 3 additions & 3 deletions api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
}
},

signin: function(req, res) {
signup: function(req, res) {

try {

Expand All @@ -63,7 +63,7 @@ module.exports = {

if(r.length != 0) {

_res.json({
response(_res).json({
result: "error",
message: "email already in database"
})
Expand All @@ -75,7 +75,7 @@ module.exports = {

model.save(_user, function(r){

_res.json({
response(_res).json({
result: "success",
message: "user created successfully"
});
Expand Down
23 changes: 12 additions & 11 deletions client/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@
// prepare successful login callback
broadcast.once("user/logout/success", function(data) {

alert(data.message || "User successfully logged out.");
alert("Result: " + data.message || "User successfully logged out.");
core.client.render("/");

});

// prepare error login callback
broadcast.once("user/logout/error", function(data) {
broadcast.once("user/logout/error", function(data) {
alert("Error: "+ data.message || "unknown error.");
});

// call the api
sandbox.api("user/logout", function(response) {
sandbox.api("user/logout", {}, function(response) {

broadcast.publish("user/logout/" + response.result, response || {});

Expand All @@ -82,12 +82,14 @@

// prepare successful login callback
broadcast.subscribe("user/signup/success", function(data) {

var user_info = sandbox.client("#user-info");
user_info.show();

alert("Result: " + data.message || "User created successfully");

if($("#destination").val())
core.client.render("login?destination=" + encodeURI($("#destination").val()));

var user = sandbox.client("#user");
user.html(data.name);
else
core.client.render("dashboard");
});

// prepare error login callback
Expand All @@ -96,16 +98,15 @@
});

// call the api
sandbox.api("user/signin", {
sandbox.api("user/signup", {

name: $("#name").val(),
email: $("#email").val(),
password: $("#password").val()

}, function(response) {

broadcast.publish("user/signin/" + response.result,
response.data.user || {});
broadcast.publish("user/signup/" + response.result, response || {});
});

}; exports.signup = signup;
Expand Down
3 changes: 2 additions & 1 deletion routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ module.exports = {
// views
"/": "home",
"/login": "home/login",
"/signup": "home/signup",
"/dashboard": "home/dashboard",

// api
"/api/user": "user",
"/api/user/signin": "user/signin",
"/api/user/signup": "user/signup",
"/api/user/login": "user/login",
"/api/user/logout": "user/logout",

Expand Down
5 changes: 4 additions & 1 deletion views/home/index.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<!DOCTYPE html>

Welcome! Do you want to <a href="login">login</a>?
Welcome!

<br />
<br /><a href="signup">Sign-up</a> | <a href="login">Login</a>
17 changes: 17 additions & 0 deletions views/home/signup.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>

<form data-module="user" data-method="signup">
<br><input type="text" id="name" placeholder="name">
<br><input type="text" id="email" placeholder="[email protected]">
<br><input type="password" id="password" placeholder="12345678">

<% if(destination){ %>
<input type="hidden" id="destination" value="<%= destination %>">
<% } %>

<input type="submit" value="Sign-up">
</form>

<br />

<a href="/">Back</a>
10 changes: 6 additions & 4 deletions views/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
</head>
<body>

<div class="header">
<section class="header">
<b>Title:</b> <%- title %>
<div>

<br />

<div class="content" data-container="controllers">
<%- body %>
</div>
<section class="content">
<div data-container="controllers">
<%- body %>
</div>
</section>

<!-- system deps -->
<script src="/socket.io/socket.io.js"></script>
Expand Down

0 comments on commit 83bf8fb

Please sign in to comment.