Permalink
Browse files

added all files

  • Loading branch information...
Grigore147 committed Sep 27, 2012
1 parent e6a0c9a commit 06c3581517bc230b097a5602ab5e3d6029b6caa0
Showing with 748 additions and 3 deletions.
  1. +2 −3 README.md
  2. +22 −0 auth.js
  3. +68 −0 config/development/auth.js
  4. +10 −0 config/development/routing.js
  5. +122 −0 controllers/actions.js
  6. +25 −0 controllers/auth.js
  7. +40 −0 models/user.js
  8. +30 −0 package.json
  9. +418 −0 user.js
  10. +5 −0 views/login.html
  11. +6 −0 views/register.html
View
@@ -1,4 +1,3 @@
-Katana-auth
-===========
+# [Auth](http://github.com/Shogun147/Katana-Auth)
-Base authorization and authentication module with roles and rights
+Base authorization and authentication module with roles and rights
View
22 auth.js
@@ -0,0 +1,22 @@
+var User = require('./user');
+
+Class('Katana.Module.Auth', {
+ isa: Katana.Core.Module,
+
+ have: {
+ name: 'auth',
+ user: User
+ },
+
+ methods: {}
+});
+
+module.exports = new Katana.Module.Auth;
+
+App.on('request', function(Request, Response, callback) {
+ new User(Request.session, function(user) {
+ Request.user = user;
+
+ callback();
+ });
+});
View
@@ -0,0 +1,68 @@
+module.exports = {
+ store: 'mongoose',
+
+ allow_registration: true,
+ accounts_per_email: 1,
+ accounts_per_ip: 5,
+ password_case_sensitive: false,
+ login_on_signup: true,
+
+ username_pattern: new RegExp('^[-_a-z0-9]{3,25}$', 'i'),
+ salt: '12345',
+
+ allow_username: true,
+ allow_email: true,
+ attempts_limit: 5,
+ attempts_expire: 60*60*24,
+
+ password_recovery: true,
+ password_recovery_expire: 60*60*24,
+
+ domain: 'http://localhost:8000/',
+
+ login_url: '/',
+ register_url: '/',
+ logout_url: '/',
+
+ email_confirmation: false,
+ email_confirmation_expire: 60*60*24*7,
+
+ email: {
+ smtp: {
+ service: 'Gmail',
+ username: 'gmail@email',
+ password: 'password'
+ },
+
+ from: 'from@email'
+ },
+
+ register_email: {
+ subject: 'Welcome to our site!',
+ text: 'COPY AND OPEN THIS LINK IN BROWSER TO CONFIRM YOUR EMAIL: [domain]account/actions/confirm_email/[username]/[key]',
+ html: '<a href="[domain]account/actions/confirm_email/[username]/[key]"><h3>CLICK THIS LINK TO CONFIRM YOUR EMAIL</h3></a>'
+ // template: 'email_templates/register'
+ },
+
+ new_password_request_email: {
+ subject: 'Password recovery',
+ text: 'COPY AND OPEN THIS LINK IN BROWSER TO GENERATE NEW PASSWORD: [domain]account/actions/generate_new_password/[username]/[key]',
+ html: '<a href="[domain]account/actions/generate_new_password/[username]/[key]"><h3>CLICK THIS LINK TO GENERATE NEW PASSWORD</h3></a>'
+ // template: 'email_templates/password_recovery'
+ },
+
+ new_password_email: {
+ subject: 'New password',
+ text: 'THIS IS YOUR NEW PASSWORD, PLEASE CHANGE IT AFTER LOGIN: [password]',
+ html: '<h3>THIS IS YOUR NEW PASSWORD, PLEASE CHANGE IT AFTER LOGIN: [password]</h3>'
+ // template: 'email_templates/new_password'
+ }
+}
+
+var App = global.App;
+
+var Session = App.Config().session;
+
+Session.defaults.logged_in = false;
+Session.defaults.user_id = null;
+
@@ -0,0 +1,10 @@
+module.exports = {
+ route: {
+ controller: 'auth',
+ action: 'index'
+ },
+
+ routes: [
+
+ ]
+}
View
@@ -0,0 +1,122 @@
+Class('Auth_Actions_Controller', {
+ methods: {
+ index: function(Response, Request) {
+ Response.redirect();
+ },
+
+ login: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ return (Request.is_ajax ? Response.send({ error: null }) : Response.redirect());
+ }
+
+ var data = Request.data;
+
+ User.login(data.username, data.password, Request.client.ip, function(error) {
+ Request.is_ajax ? Response.send({ error: error }) : Response.redirect();
+ });
+ },
+
+ logout: function(Response, Request) {
+ var User = Request.user;
+
+ User.logout();
+
+ Response.redirect();
+ },
+
+ register: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ Request.is_ajax ? Response.send({ error: null }) : Response.redirect();
+ }
+
+ var data = Request.data;
+
+ User.register(data.username, data.password, data.email, Request.client.ip, function(error) {
+ Request.is_ajax ? Response.send({ error: error }) : Response.redirect();
+ });
+ },
+
+ confirm_email: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ return Response.redirect();
+ }
+
+ var username = Request.arguments[0];
+ var key = Request.arguments[1];
+
+ User.confirm_email(username, key, function(error) {
+ console.log(error || 'email_confirmed')
+ });
+ },
+
+ recover_password: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ return Response.redirect();
+ }
+
+ Response.send('recover_password');
+ },
+
+ generate_new_password: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ return Response.redirect();
+ }
+
+ Response.send('generate_new_password');
+ },
+
+ _404: function(Response) {
+ Response.redirect();
+ }
+ }
+});
+
+module.exports = new Auth_Actions_Controller;
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
View
@@ -0,0 +1,25 @@
+Class('Auth_Auth_Controller', {
+ methods: {
+ login: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ return Response.redirect();
+ }
+
+ Response.render('auth:login');
+ },
+
+ signup: function(Response, Request) {
+ var User = Request.user;
+
+ if (User.logged_in()) {
+ return Response.redirect();
+ }
+
+ Response.render('auth:register');
+ }
+ }
+});
+
+module.exports = new Auth_Auth_Controller;
View
@@ -0,0 +1,40 @@
+var config = App.Config('auth:');
+
+var Mongoose = App.Store(config.store);
+var Schema = require('mongoose').Schema;
+
+var User = new Schema({
+ username: { type: String, required: true, index: { unique: true } },
+ password: { type: String, required: true },
+ email: { type: String, index: { unique: (config.accounts_per_email === 1) } },
+ class: String,
+ roles: [{ type: Schema.ObjectId, ref: 'roles' }],
+ status: Number,
+ signup_time: { type: Date },
+ signup_ip: String,
+ online: { type: Boolean, default: false },
+ last_login: Date,
+ last_action: Date,
+ last_login_ip: String,
+ np_request_key: String,
+ np_request_time: Date,
+ email_confirmed: Boolean,
+ banned: Boolean,
+ avatar: String
+});
+
+module.exports = Mongoose.model('users', User);
+
+var Role = new Schema({
+ name: { type: String, index: { unique: true } }
+});
+
+Mongoose.model('roles', Role);
+
+var Right = new Schema({
+ name: { type: String, index: { unique: true } },
+ roles: [{ type: Schema.ObjectId, ref: 'roles' }]
+});
+
+Mongoose.model('rights', Right);
+
View
@@ -0,0 +1,30 @@
+{
+ "name": "auth",
+ "description": "Basic authorization and authentication module with roles and rights",
+ "version": "0.1.0",
+
+ "author": "Shogun <Shogun147@gmail.com> (http://github.com/Shogun147)",
+ "contributors": [
+ { "name": "Shogun", "email": "Shogun147@gmail.com" }
+ ],
+
+ "keywords": ["auth", "authorization", "authentication", "roles", "rights", "users"],
+
+ "homepage": "http://katanajs.com/modules/auth (comming soon)",
+
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Shogun147/Katana-Auth.git",
+ "web": "https://github.com/Shogun147/Katana-Auth"
+ },
+
+ "bugs": {
+ "url": "https://github.com/Shogun147/Katana-Auth/issues"
+ },
+
+ "dependencies": {
+
+ },
+
+ "main": "./auth"
+}
Oops, something went wrong.

0 comments on commit 06c3581

Please sign in to comment.