Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated mailer code

  • Loading branch information...
commit 806a6dbc33417ae8d688a66ae1d9f53341d1fc6e 1 parent 653e526
@NoamB authored
View
2  README.rdoc
@@ -1 +1 @@
-Under construction
+This is an example of using Sorcery with Sinatra.
View
3  authentication.rb
@@ -1,3 +0,0 @@
-class Authentication < ActiveRecord::Base
- belongs_to :user
-end
View
BIN  dummy
Binary file not shown
View
4 models/sorcery_mailer.rb
@@ -4,14 +4,14 @@ class SorceryMailer < ActionMailer::Base
def activation_needed_email(user)
@user = user
- @url = "http://example.com/login"
+ @url = "http://0.0.0.0:4567/users/#{user.activation_code}/activate"
mail(:to => user.email,
:subject => "Welcome to My Awesome Site")
end
def activation_success_email(user)
@user = user
- @url = "http://example.com/login"
+ @url = "http://0.0.0.0:4567/login"
mail(:to => user.email,
:subject => "Your account is now activated")
end
View
26 myapp.rb
@@ -11,9 +11,21 @@
:verbosity => "quiet"
)
+# mailer
require 'action_mailer'
-ActionMailer::Base.perform_deliveries = false
-ActionMailer::Base.raise_delivery_errors = false
+ActionMailer::Base.perform_deliveries = true
+ActionMailer::Base.raise_delivery_errors = true
+ActionMailer::Base.smtp_settings = {
+ :address => "smtp.gmail.com",
+ :port => 587,
+ :domain => 'example.com',
+ :user_name => 'nbenari',# put your real username here to send emails.
+ :password => 'secret', # put your real password here to send emails.
+ :authentication => 'plain',
+ :enable_starttls_auto => true
+}
+
+ActionMailer::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
require File.join(File.dirname(__FILE__),'models','sorcery_mailer')
@@ -82,6 +94,16 @@
end
end
+get '/users/:id/activate' do
+ if @user = User.load_from_activation_token(params[:id])
+ @user.activate!
+ session[:notice] = 'User was successfully activated.'
+ redirect '/login'
+ else
+ not_authenticated
+ end
+end
+
# login/logout
get '/login' do
erb :'user_sessions/new'
View
25 sorcery_mailer.rb
@@ -1,25 +0,0 @@
-class SorceryMailer < ActionMailer::Base
-
- default :from => "notifications@example.com"
-
- def activation_needed_email(user)
- @user = user
- @url = "http://example.com/login"
- mail(:to => user.email,
- :subject => "Welcome to My Awesome Site")
- end
-
- def activation_success_email(user)
- @user = user
- @url = "http://example.com/login"
- mail(:to => user.email,
- :subject => "Your account is now activated")
- end
-
- def reset_password_email(user)
- @user = user
- @url = "http://example.com/login"
- mail(:to => user.email,
- :subject => "Your password has been reset")
- end
-end
View
24 user.rb
@@ -1,24 +0,0 @@
-class User < ActiveRecord::Base
- attr_accessible :email, :password, :password_confirmation, :authentications_attributes
-
- 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
30 views/password_resets/_form.html.erb
@@ -1,30 +0,0 @@
-<%= 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 %>
View
5 views/password_resets/edit.html.erb
@@ -1,5 +0,0 @@
-<h1>Reset Password</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', users_path %>
View
0  views/user_mailer/activation_needed_email.html.erb → ...s/sorcery_mailer/activation_needed_email.html.erb
File renamed without changes
View
0  views/user_mailer/activation_needed_email.text.erb → ...s/sorcery_mailer/activation_needed_email.text.erb
File renamed without changes
View
0  views/user_mailer/activation_success_email.html.erb → .../sorcery_mailer/activation_success_email.html.erb
File renamed without changes
View
0  views/user_mailer/activation_success_email.text.erb → .../sorcery_mailer/activation_success_email.text.erb
File renamed without changes
View
0  views/user_mailer/reset_password_email.html.erb → views/sorcery_mailer/reset_password_email.html.erb
File renamed without changes
View
0  views/user_mailer/reset_password_email.text.erb → views/sorcery_mailer/reset_password_email.text.erb
File renamed without changes
View
6 views/user_sessions/_forgot_password_form.html.erb
@@ -1,6 +0,0 @@
-<%= 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 %>
View
17 views/user_sessions/_form.html.erb
@@ -1,17 +0,0 @@
-<%= 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 %>
View
6 views/user_sessions/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing user_session</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @user_session %> |
-<%= link_to 'Back', user_sessions_path %>
View
9 views/user_sessions/new.html.erb
@@ -1,9 +0,0 @@
-<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
6 views/users/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing user</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @user %> |
-<%= link_to 'Back', users_path %>
View
9 views/users/show.html.erb
@@ -1,9 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <b>User:</b>
- <%= @user.email %>
-</p>
-
-<%= link_to 'Edit', edit_user_path(@user) %> |
-<%= link_to 'Back', users_path %>
Please sign in to comment.
Something went wrong with that request. Please try again.