Skip to content
Browse files

Adding sendgrid and auto login after signup functionality

  • Loading branch information...
1 parent b05e4e7 commit 2d8f86fe304809c7dee32c4f24a1b3508050b6ee Rian Rainey committed Mar 26, 2013
View
42 app/controllers/registrations_controller.rb
@@ -0,0 +1,42 @@
+class RegistrationsController < Devise::RegistrationsController
+ def new
+ super
+ end
+
+ def create
+ build_resource
+
+ if resource.save
+ if resource.active_for_authentication?
+ binding.pry
+ Notifier.signup_email(params[:user]).deliver
+
+ set_flash_message :notice, :signed_up if is_navigational_format?
+ sign_up(resource_name, resource)
+ respond_with resource, :location => after_sign_up_path_for(resource)
+ else
+ set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
+ expire_session_data_after_sign_in!
+ respond_with resource, :location => after_inactive_sign_up_path_for(resource)
+ end
+ else
+ clean_up_passwords resource
+ respond_with resource
+ end
+
+
+
+
+
+ end
+
+ def update
+ super
+ end
+
+ # Signs in a user on sign up.
+ def sign_up(resource_name, resource)
+ sign_in(resource_name, resource)
+ end
+
+end
View
2 app/controllers/users_controller.rb
@@ -29,7 +29,7 @@ def edit
# PUT /users/1
# PUT /users/1.json
def update
- params[:user][:role_ids] ||= nil
+ #params[:user][:role_ids] ||= nil
@user = User.find(params[:id])
respond_to do |format|
View
5 app/controllers/workouts_controller.rb
@@ -10,7 +10,10 @@ def index
def individual_workouts
@entries = Entry.find_all_by_user_id(params[:user_id])
- @workout = Workout.find_by_id(@entries.first.workout_id)
+
+ unless @entries.empty?
+ @workout = Workout.find_by_id(@entries.first.workout_id)
+ end
respond_to do |format|
format.html
View
10 app/models/notifier.rb
@@ -0,0 +1,10 @@
+class Notifier < ActionMailer::Base
+ default :from => "crossfit@rianrainey.com"
+
+ # send a signup email to the user, pass in the user object that contains the user’s email address
+ def signup_email(user)
+ mail( :to => user[:email],
+ :subject => "Thanks for signing up" )
+ end
+end
+
View
2 app/models/role.rb
@@ -1,4 +1,4 @@
class Role < ActiveRecord::Base
- attr_accessible :name
+ #attr_accessible :name
has_and_belongs_to_many :user
end
View
4 app/models/workout.rb
@@ -1,6 +1,6 @@
class Workout < ActiveRecord::Base
attr_accessible :body, :title
- has_many :workouts
- has_many :users, :through => :workouts
+ has_many :entries
+ has_many :users, :through => :entries
end
View
27 app/views/registrations/new.html.erb
@@ -0,0 +1,27 @@
+<h2>Sign up</h2>
+
+<%= devise_error_messages! %>
+
+<div class="offset4 span6">
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
+
+ <div><%= f.label :email %>
+ <%= f.email_field :email, :class => "input-xlarge" %>
+ </div>
+
+ <div><%= f.label :password %>
+ <%= f.password_field :password, :class => "input-xlarge" %>
+ </div>
+
+ <div><%= f.label :password_confirmation %>
+ <%= f.password_field :password_confirmation, :class => "input-xlarge" %>
+ </div>
+
+ <div><%= f.submit "Sign up", :class => "btn btn-primary" %></div>
+
+ <% end %>
+
+ <%= render "devise/shared/links" %>
+</div>
+
+<div class="clear"></div>
View
3 app/views/workouts/individual_workouts.html.erb
@@ -8,6 +8,7 @@
</tr>
<tr>
+ <% if @workout %>
<td><%= @workout.title %></td>
<td><%= @workout.body %></td>
<td>
@@ -18,7 +19,7 @@
</ul>
<% end %>
</td>
-
+ <% end %>
</tr>
</table>
View
11 config/environment.rb
@@ -3,3 +3,14 @@
# Initialize the rails application
CfwnApp::Application.initialize!
+
+# SendGrid
+ActionMailer::Base.smtp_settings = {
+ :user_name => "app9159834@heroku.com",
+ :password => "rdbv5bsw",
+ :domain => "yourdomain.com",
+ :address => "smtp.sendgrid.net",
+ :port => 587,
+ :authentication => :plain,
+ :enable_starttls_auto => true
+}
View
5 config/routes.rb
@@ -1,10 +1,7 @@
CfwnApp::Application.routes.draw do
- devise_for :users
+ devise_for :users, :controllers => { :registrations => 'registrations' }
-# get "workouts/index"
-
- #resources :workouts
match '/workouts/individual/:user_id/',
:as => 'my_workout',
:controller => 'workouts',

0 comments on commit 2d8f86f

Please sign in to comment.
Something went wrong with that request. Please try again.