Permalink
Browse files

registration working

  • Loading branch information...
1 parent 121afd9 commit 9e80a4a2043ccce951575e3c206a61f36c48e8d2 @NoamB committed Mar 25, 2011
Showing with 288 additions and 5 deletions.
  1. +13 −0 Rakefile
  2. +1 −2 db/migrate/{core → }/20101224223620_create_users.rb
  3. 0 ...activation/20101224223622_add_activation_to_users.rb → 20101224223621_add_activation_to_users.rb}
  4. 0 db/migrate/{reset_password → }/20101224223622_add_reset_password_to_users.rb
  5. 0 db/migrate/{remember_me → }/20101224223623_add_remember_me_token_to_users.rb
  6. 0 db/migrate/{activity_logging → }/20101224223624_add_activity_logging_to_users.rb
  7. 0 ...6_add_brute_force_protection_to_users.rb → 20101224223625_add_brute_force_protection_to_users.rb}
  8. 0 ...grate/{oauth/20101224223628_create_authentications.rb → 20101224223626_create_authentications.rb}
  9. BIN dummy
  10. +45 −2 myapp.rb
  11. +18 −0 user.rb
  12. +0 −1 views/index.erb
  13. +30 −0 views/password_resets/_form.html.erb
  14. +5 −0 views/password_resets/edit.html.erb
  15. +17 −0 views/user_mailer/activation_needed_email.html.erb
  16. +9 −0 views/user_mailer/activation_needed_email.text.erb
  17. +17 −0 views/user_mailer/activation_success_email.html.erb
  18. +9 −0 views/user_mailer/activation_success_email.text.erb
  19. +16 −0 views/user_mailer/reset_password_email.html.erb
  20. +8 −0 views/user_mailer/reset_password_email.text.erb
  21. +6 −0 views/user_sessions/_forgot_password_form.html.erb
  22. +17 −0 views/user_sessions/_form.html.erb
  23. +6 −0 views/user_sessions/edit.html.erb
  24. +9 −0 views/user_sessions/new.html.erb
  25. +21 −0 views/users/_form.erb
  26. +6 −0 views/users/edit.html.erb
  27. +21 −0 views/users/index.erb
  28. +5 −0 views/users/new.erb
  29. +9 −0 views/users/show.html.erb
View
@@ -0,0 +1,13 @@
+
+task :environment do
+ require_relative 'myapp'
+end
+
+namespace :db do
+ desc "Migrate the database"
+ task(:migrate => :environment) do
+ ActiveRecord::Base.logger = Logger.new(STDOUT)
+ ActiveRecord::Migration.verbose = true
+ ActiveRecord::Migrator.migrate("db/migrate")
+ end
+end
@@ -1,8 +1,7 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
- t.string :username, :null => false
- t.string :email, :default => nil
+ t.string :email, :null => false
t.string :crypted_password, :default => nil
t.string :salt, :default => nil
View
BIN dummy
Binary file not shown.
View
@@ -12,11 +12,34 @@
)
require 'action_mailer'
+ActionMailer::Base.perform_deliveries = false
+ActionMailer::Base.raise_delivery_errors = false
+
require File.join(File.dirname(__FILE__),'sorcery_mailer')
# models
-require File.join(File.dirname(__FILE__),'user')
require 'sorcery'
+Sorcery::Controller::Config.submodules = [:user_activation, :http_basic_auth, :remember_me, :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :oauth]
+Sinatra::Application.activate_sorcery! do |config|
+ config.session_timeout = 10.minutes
+ config.session_timeout_from_last_action = false
+
+ config.controller_to_realm_map = {"application" => "Application", "users" => "Users"}
+
+ config.oauth_providers = [:twitter, :facebook]
+
+ config.twitter.key = "eYVNBjBDi33aa9GkA3w"
+ config.twitter.secret = "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8"
+ config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
+ config.twitter.user_info_mapping = {:email => "screen_name"}
+
+ config.facebook.key = "34cebc81c08a521bc66e212f947d73ec"
+ config.facebook.secret = "5b458d179f61d4f036ee66a497ffbcd0"
+ config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
+ config.facebook.user_info_mapping = {:email => "name"}
+end
+require File.join(File.dirname(__FILE__),'authentication')
+require File.join(File.dirname(__FILE__),'user')
# filters
['/test_logout','/some_action','/test_should_be_logged_in'].each do |patt|
@@ -31,9 +54,29 @@
# actions
get '/' do
- erb :index
+ @notice = session[:notice]
+ @alert = session[:alert]
+ session.clear
+ @users = User.all
+ erb :'users/index'
+end
+
+get '/users/new' do
+ erb :'users/new'
+end
+
+post '/users' do
+ @user = User.new(params[:user])
+ if @user.save
+ session[:notice] = "Success!"
+ redirect '/'
+ else
+ session[:alert] = "Failed!"
+ redirect '/'
+ end
end
+# blalll
get '/test_login' do
@user = login(params[:username],params[:password])
@current_user = current_user
View
18 user.rb
@@ -3,4 +3,22 @@ class User < ActiveRecord::Base
has_many :authentications, :dependent => :destroy
accepts_nested_attributes_for :authentications
+ validates_confirmation_of :password, :on => :create, :message => "should match confirmation"
+
+ activate_sorcery! do |config|
+ config.username_attribute_name = :email
+
+ config.user_activation_mailer = SorceryMailer
+
+ config.reset_password_mailer = SorceryMailer
+ config.reset_password_expiration_period = 10.minutes
+ config.reset_password_time_between_emails = nil
+
+ config.activity_timeout = 1.minutes
+
+ config.consecutive_login_retries_amount_limit = 10
+ config.login_lock_time_period = 2.minutes
+
+ config.authentications_class = Authentication
+ end
end
View
@@ -1 +0,0 @@
-InDeX!!
@@ -0,0 +1,30 @@
+<%= form_for @user, :url => password_reset_path(@user), :html => {:method => :put} do |f| %>
+ <% if @user.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= @user.email %>
+ </div>
+ <div class="field">
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </div>
+ <div class="field">
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ <%= hidden_field_tag :token, @token %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,5 @@
+<h1>Reset Password</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', users_path %>
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Welcome to example.com, <%= @user.email %></h1>
+ <p>
+ You have successfully signed up to example.com,
+ your username is: <%= @user.email %>.<br/>
+ </p>
+ <p>
+ To login to the site, just follow this link: <%= @url %>.
+ </p>
+ <p>Thanks for joining and have a great day!</p>
+ </body>
+</html>
@@ -0,0 +1,9 @@
+Welcome to example.com, <%= @user.email %>
+===============================================
+
+You have successfully signed up to example.com,
+your username is: <%= @user.email %>.
+
+To login to the site, just follow this link: <%= @url %>.
+
+Thanks for joining and have a great day!
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Congratz, <%= @user.email %></h1>
+ <p>
+ You have successfully activated your example.com account,
+ your username is: <%= @user.email %>.<br/>
+ </p>
+ <p>
+ To login to the site, just follow this link: <%= @url %>.
+ </p>
+ <p>Thanks for joining and have a great day!</p>
+ </body>
+</html>
@@ -0,0 +1,9 @@
+Congratz, <%= @user.email %>
+===============================================
+
+You have successfully activated your example.com account,
+your username is: <%= @user.email %>.
+
+To login to the site, just follow this link: <%= @url %>.
+
+Thanks for joining and have a great day!
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
+ </head>
+ <body>
+ <h1>Hello, <%= @user.email %></h1>
+ <p>
+ You have requested to reset your password.
+ </p>
+ <p>
+ To choose a new password, just follow this link: <%= @url %>.
+ </p>
+ <p>Have a great day!</p>
+ </body>
+</html>
@@ -0,0 +1,8 @@
+Hello, <%= @user.email %>
+===============================================
+
+You have requested to reset your password.
+
+To choose a new password, just follow this link: <%= @url %>.
+
+Have a great day!
@@ -0,0 +1,6 @@
+<%= form_tag password_resets_path, :method => :post do %>
+ <div class="field">
+ <%= label_tag :email %><br />
+ <%= text_field_tag :email %> <%= submit_tag "Reset my password!" %>
+ </div>
+<% end %>
@@ -0,0 +1,17 @@
+<%= form_tag user_sessions_path, :method => :post do %>
+ <div class="field">
+ <%= label_tag :email %><br />
+ <%= text_field_tag :email %>
+ </div>
+ <div class="field">
+ <%= label_tag :password %><br />
+ <%= password_field_tag :password %>
+ </div>
+ <div class="actions">
+ <%= submit_tag "Login" %>
+ </div>
+ <div>
+ <%= label_tag "keep me logged in" %><br />
+ <%= check_box_tag :remember %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing user_session</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user_session %> |
+<%= link_to 'Back', user_sessions_path %>
@@ -0,0 +1,9 @@
+<h1>Login</h1>
+<p id="notice"><%= notice %></p>
+<p id="alert"><%= alert %></p>
+<%= render 'form' %>
+
+<h1>Forgot Password?</h1>
+<%= render 'forgot_password_form' %>
+
+<%= link_to 'Back', user_sessions_path %>
View
@@ -0,0 +1,21 @@
+<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
+ <div style="margin:0;padding:0;display:inline">
+ <input name="utf8" type="hidden"/>
+ <input name="authenticity_token" type="hidden" value="UWWeMk7acxI1kbZFEQBtIrn7iY6TiCOZlMFL0mOsxPc=" /></div>
+
+ <div class="field">
+ <label for="user_email">Email</label><br />
+ <input id="user_email" name="user[email]" size="30" type="text" />
+ </div>
+ <div class="field">
+ <label for="user_password">Password</label><br />
+ <input id="user_password" name="user[password]" size="30" type="password" />
+ </div>
+ <div class="field">
+ <label for="user_password_confirmation">Password confirmation</label><br />
+ <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
+ </div>
+ <div class="actions">
+ <input id="user_submit" name="commit" type="submit" value="Create User" />
+ </div>
+</form>
@@ -0,0 +1,6 @@
+<h1>Editing user</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @user %> |
+<%= link_to 'Back', users_path %>
View
@@ -0,0 +1,21 @@
+<h1>Listing users</h1>
+<p id="notice"><%= @notice %></p>
+<p id="alert"><%= @alert %></p>
+<table>
+ <tr>
+ <th>User</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.email %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<a href=<%= url('/users/new') %>>New User</a>
View
@@ -0,0 +1,5 @@
+<h1>New user</h1>
+
+<%= erb :'users/_form' %>
+
+<a href=<%= url('/') %>>Back</a>
@@ -0,0 +1,9 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>User:</b>
+ <%= @user.email %>
+</p>
+
+<%= link_to 'Edit', edit_user_path(@user) %> |
+<%= link_to 'Back', users_path %>

0 comments on commit 9e80a4a

Please sign in to comment.