Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Checking in work for logging in/registering

  • Loading branch information...
commit 48bf2d64d4db07efc7da1b89816a8bed0643cbcf 1 parent af7dee5
David Petersen authored
View
8 assets/images/login.svg
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ width="60px" height="100px" viewBox="0 0 60 100" enable-background="new 0 0 60 100" xml:space="preserve">
+<path d="M30,46.176l-15,1.323V23c0-8.271,6.729-15,15-15s15,6.729,15,15v13h8V23C53,10.317,42.683,0,30,0S7,10.317,7,23v25.205
+ l-7,0.617v48.529L30,100l30-2.648V48.822L30,46.176z"/>
+</svg>
View
24 assets/images/register.svg
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 14.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 43363) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
+<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+ width="100px" height="85.416px" viewBox="0 0 100 85.416" enable-background="new 0 0 100 85.416" xml:space="preserve">
+<g>
+ <path d="M60.082,20.987H39.918c-3.231,0-5.851,2.618-5.851,5.85v27.44c0,3.231,2.62,5.852,5.851,5.852h0.033v19.436
+ c0,3.231,2.546,5.852,5.689,5.852h8.722c3.14,0,5.688-2.62,5.688-5.852V60.129h0.032c3.231,0,5.851-2.62,5.851-5.852v-27.44
+ C65.932,23.605,63.313,20.987,60.082,20.987z"/>
+ <circle cx="50" cy="9.55" r="9.55"/>
+</g>
+<g>
+ <path d="M94.986,23.268H77.708c-2.771,0-5.014,2.245-5.014,5.014v23.514c0,2.771,2.243,5.016,5.014,5.016h0.028v16.654
+ c0,2.77,2.182,5.014,4.873,5.014h7.475c2.691,0,4.874-2.244,4.874-5.014V56.811h0.027c2.771,0,5.015-2.245,5.015-5.016V28.281
+ C100,25.513,97.756,23.268,94.986,23.268z"/>
+ <circle cx="86.347" cy="13.469" r="8.184"/>
+</g>
+<g>
+ <path d="M22.292,23.268H5.014C2.245,23.268,0,25.513,0,28.281v23.514c0,2.771,2.245,5.016,5.014,5.016h0.028v16.654
+ c0,2.77,2.184,5.014,4.874,5.014h7.474c2.692,0,4.874-2.244,4.874-5.014V56.811h0.028c2.769,0,5.014-2.245,5.014-5.016V28.281
+ C27.305,25.513,25.06,23.268,22.292,23.268z"/>
+ <circle cx="13.653" cy="13.469" r="8.183"/>
+</g>
+</svg>
View
5 assets/js/client.js
@@ -42,6 +42,11 @@ $(function() {
irc.me.set('nick', data.message.args[0]);
});
+ irc.socket.on('login_success', function(data) {
+ irc.chatWindows.add({name: 'status', type: 'status'});
+ irc.appView.render();
+ });
+
irc.socket.on('notice', function(data) {
//TODO: make this work
//irc.chatWindows.getByName('status').stream.add({sender: 'notice', raw: data.text, type: 'notice'});
View
38 assets/js/views/overview.js
@@ -5,6 +5,8 @@ var OverviewView = Backbone.View.extend({
events: {
'click #connect-button': 'connect',
+ 'click #login-button': 'login_register',
+ 'click #register-button': 'login_register',
'keypress': 'connectOnEnter'
},
@@ -27,7 +29,15 @@ var OverviewView = Backbone.View.extend({
connectOnEnter: function(event) {
if (event.keyCode !== 13) return;
- this.connect(event);
+ if($('#connect-button').length){
+ this.connect(event);
+ }
+ if($('#login-button').length){
+ this.login_register(event);
+ }
+ if($('#register-button').length){
+ this.login_register(event);
+ }
},
connect: function(event) {
@@ -55,5 +65,31 @@ var OverviewView = Backbone.View.extend({
irc.me.on('change:nick', irc.appView.renderUserBox);
irc.socket.emit('connect', connectInfo);
}
+ },
+
+ login_register: function(event) {
+ var action = event.target.innerText.toLowerCase();
+ event.preventDefault();
+ $('.error').removeClass('error');
+ var username = $('#' + action + '-username').val();
+ var password = $('#' + action + '-password').val();
+ if (!username) {
+ $('#' + action + '-username').closest('.clearfix').addClass('error');
+ $('#' + action + '-username').addClass('error');
+ }
+ if (!password) {
+ $('#' + action + '-password').closest('.clearfix').addClass('error');
+ $('#login-password').addClass('error');
+ }
+ if(username && password){
+ $('form').append(ich.load_image());
+ $('#' + action + '-button').addClass('disabled');
+ }
+
+ irc.socket.emit(action, {
+ username: username,
+ password: password
+ });
}
+
});
View
30 lib/irchandler.js
@@ -5,7 +5,7 @@ var irc = require('irc'),
Schema = mongoose.Schema;
var UserSchema = new Schema({
- username: String,
+ username: { type: String , index: {unique: true}},
password: String
});
@@ -43,24 +43,30 @@ var irchandler = exports.irchandler = function(socket) {
user.password = hash;
user.save();
console.log(user);
+ socket.emit('register_success', {username: user.username});
});
});
});
socket.on('login', function(data){
- console.log(data);
- User.find({}, function(err, docs) { console.log(docs); });
User.findOne({username: data.username}, function(err, user) {
console.log(user);
- bcrypt.compare(data.password, user.password, function(err, res) {
- socket.emit('loginStatus', {res: res});
- if(res === true){
- //client.logged_in = true;
- console.log('logged in');
- } else {
- console.log('Wrong password');
- }
- });
+ if(user){
+ bcrypt.compare(data.password, user.password, function(err, res) {
+ socket.emit('loginStatus', {res: res});
+ if(res === true){
+ //client.logged_in = true;
+ socket.emit('login_success', {username: user.username});
+ console.log('logged in');
+ } else {
+ socket.emit('login_error', {message: 'Wrong password'});
+ console.log('Wrong password');
+ }
+ });
+ } else {
+ socket.emit('login_error', {message: 'No user found'});
+ console.log('No user found');
+ }
});
});
View
65 views/templates.jade
@@ -12,20 +12,6 @@ script(id="chat_application", type="text/html")
script(id="load_image", type="text/html")
img(id="loading_image", src="/assets/images/loading.gif")
-script(id="overview_connection", type="text/html")
- #home_parent
- a.overview_button#home Home
- form.form-horizontal
- .control-group
- label(for="connect-server") Server
- .controls
- input#connect-server(type="text")
- .control-group
- label(for="connect-nick") Nick
- .controls
- input#connect-nick(type="text")
- button(id="connect-button", class="btn btn-primary") Connect
-
script(id="overview_home", type="text/html")
ul
li.overview_button#connection
@@ -37,14 +23,59 @@ script(id="overview_home", type="text/html")
li.overview_button#login
img(src="/assets/images/login.svg")
span Login
+ li.overview_button#register
+ img(src="/assets/images/register.svg")
+ span Register
script(id="overview", type="text/html")
#overview
+script(id="overview_connection", type="text/html")
+ #home_parent
+ a.overview_button#home Home
+ form.form-horizontal
+ .control-group
+ label(for="connect-server") Server
+ .controls
+ input#connect-server(type="text")
+ .control-group
+ label(for="connect-nick") Nick
+ .controls
+ input#connect-nick(type="text")
+ button(id="connect-button", class="btn btn-primary") Connect
+
script(id="overview_settings", type="text/html")
#home_parent
a.overview_button#home Home
- p Settings
+ p The Settings will go here - Don't worry I am going to get around to it...someday...
+
+script(id="overview_login", type="text/html")
+ #home_parent
+ a.overview_button#home Home
+ form.form-horizontal
+ .control-group
+ label(for="login-username") Username
+ .controls
+ input#login-username(type="text")
+ .control-group
+ label(for="login-password") Password
+ .controls
+ input#login-password(type="password")
+ button(id="login-button", class="btn btn-primary") Login
+
+script(id="overview_register", type="text/html")
+ #home_parent
+ a.overview_button#home Home
+ form.form-horizontal
+ .control-group
+ label(for="register-username") Username
+ .controls
+ input#register-username(type="text")
+ .control-group
+ label(for="register-password") Password
+ .controls
+ input#register-password(type="password")
+ button(id="register-button", class="btn btn-primary") Register
script(id="titlebar", type="text/html")
.titlebar
@@ -75,10 +106,10 @@ script(id="channel", type="text/html")
{{/notStatus}}
script(id="user_box", type="text/html")
- div
+ div
i(class="icon-user icon-white")
{{nick}}
- div
+ div
i(class="icon-asterisk icon-white")
{{server}}
Please sign in to comment.
Something went wrong with that request. Please try again.