| @@ -0,0 +1,3 @@ | |||||
| # Place all the behaviors and hooks related to the matching controller here. | |||||
| # All this logic will automatically be available in application.js. | |||||
| # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ | |||||
| @@ -0,0 +1,3 @@ | |||||
| // Place all the styles related to the PasswordResets controller here. | |||||
| // They will automatically be included in application.css. | |||||
| // You can use Sass (SCSS) here: http://sass-lang.com/ | |||||
| @@ -0,0 +1,25 @@ | |||||
| class PasswordResetsController < ApplicationController | |||||
| def create | |||||
| @user = User.find_by_email(params[:email]) | |||||
| @user.deliver_reset_password_instructions! if @user | |||||
| redirect_to(root_path, :notice => "Instructions have been sent to your email.") | |||||
| end | |||||
| def edit | |||||
| @user = User.load_from_reset_password_token(params[:id]) | |||||
| @token = params[:id] | |||||
| not_authenticated unless @user | |||||
| end | |||||
| def update | |||||
| @token = params[:token] | |||||
| @user = User.load_from_reset_password_token(params[:token]) | |||||
| not_authenticated unless @user | |||||
| @user.password_confirmation = params[:user][:password_confirmation] | |||||
| if @user.change_password!(params[:user][:password]) | |||||
| redirect_to(root_path, :notice => "Password changed OK") | |||||
| else | |||||
| render :action => "edit" | |||||
| end | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,2 @@ | |||||
| module PasswordResetsHelper | |||||
| end | |||||
| @@ -0,0 +1,14 @@ | |||||
| class UserMailer < ActionMailer::Base | |||||
| default from: "from@example.com" | |||||
| # Subject can be set in your I18n file at config/locales/en.yml | |||||
| # with the following lookup: | |||||
| # | |||||
| # en.user_mailer.reset_password_email.subject | |||||
| # | |||||
| def reset_password_email(user) | |||||
| @user = user | |||||
| @url = "http://localhost:3000/password_resets/#{user.reset_password_token}/edit" | |||||
| mail(:to => user.email, :subject => "Your password has been reset") | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,2 @@ | |||||
| %h1 PasswordResets#create | |||||
| %p Find me in app/views/password_resets/create.html.haml | |||||
| @@ -0,0 +1,32 @@ | |||||
| %h1 Choose a new password | |||||
| = form_for @user, :url => password_reset_path(@user), :html => { :method => :put } do |f| | |||||
| - if @user.errors.any? | |||||
| #error_explanation | |||||
| %h2 | |||||
| = pluralize(@user.errors.count, "error") | |||||
| prohibited this user from being saved: | |||||
| %ul | |||||
| - @user.errors.full_messages.each do |msg| | |||||
| %li= msg | |||||
| .field | |||||
| = f.label :email | |||||
| %br | |||||
| = @user.email | |||||
| .field | |||||
| = f.label :password | |||||
| %br | |||||
| = f.password_field :password | |||||
| .field | |||||
| = f.label :password_confirmation | |||||
| %br | |||||
| = f.password_field :password_confirmation | |||||
| = hidden_field_tag :token, @token | |||||
| .actions | |||||
| = f.submit | |||||
| @@ -0,0 +1,2 @@ | |||||
| %h1 PasswordResets#update | |||||
| %p Find me in app/views/password_resets/update.html.haml | |||||
| @@ -0,0 +1,7 @@ | |||||
| = form_tag password_resets_path, :method => :post do | |||||
| .field | |||||
| = label_tag :email | |||||
| %br | |||||
| = text_field_tag :email | |||||
| = submit_tag "Reset my password" | |||||
| @@ -16,4 +16,8 @@ | |||||
| = label_tag :remember_me | = label_tag :remember_me | ||||
| .actions | .actions | ||||
| = submit_tag "Log in" | |||||
| = submit_tag "Log in" | |||||
| %h1 Forgotten your password? | |||||
| = render "forgot_password_form" | |||||
| @@ -0,0 +1,10 @@ | |||||
| Hello, | |||||
| = @user.email | |||||
| You have requested to reset your password. | |||||
| To choose a new password, just follow this link: | |||||
| = @url | |||||
| Have a great day! | |||||
| @@ -28,4 +28,12 @@ Apollo::Application.configure do | |||||
| # Expands the lines which load the assets | # Expands the lines which load the assets | ||||
| config.assets.debug = true | config.assets.debug = true | ||||
| config.action_mailer.delivery_method = :smtp | |||||
| ActionMailer::Base.smtp_settings = { | |||||
| :address => "localhost", | |||||
| :port => 1025, | |||||
| :domain => "localhost:3000" | |||||
| } | |||||
| end | end | ||||
| @@ -3,7 +3,7 @@ | |||||
| # Available submodules are: :user_activation, :http_basic_auth, :remember_me, | # Available submodules are: :user_activation, :http_basic_auth, :remember_me, | ||||
| # :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external | # :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external | ||||
| # Rails.application.config.sorcery.submodules = [:remember_me, :reset_password] | # Rails.application.config.sorcery.submodules = [:remember_me, :reset_password] | ||||
| Rails.application.config.sorcery.submodules = [:remember_me] | |||||
| Rails.application.config.sorcery.submodules = [:remember_me, :reset_password] | |||||
| # Here you can configure each submodule's features. | # Here you can configure each submodule's features. | ||||
| Rails.application.config.sorcery.configure do |config| | Rails.application.config.sorcery.configure do |config| | ||||
| @@ -269,7 +269,7 @@ Rails.application.config.sorcery.configure do |config| | |||||
| # mailer class. Needed. | # mailer class. Needed. | ||||
| # Default: `nil` | # Default: `nil` | ||||
| # | # | ||||
| # user.reset_password_mailer = | |||||
| user.reset_password_mailer = UserMailer | |||||
| # reset password email method on your mailer class. | # reset password email method on your mailer class. | ||||
| @@ -4,6 +4,7 @@ Apollo::Application.routes.draw do | |||||
| resources :users | resources :users | ||||
| resources :sessions | resources :sessions | ||||
| resources :password_resets | |||||
| get "posts/near" | get "posts/near" | ||||
| @@ -0,0 +1,19 @@ | |||||
| require 'test_helper' | |||||
| class PasswordResetsControllerTest < ActionController::TestCase | |||||
| test "should get create" do | |||||
| get :create | |||||
| assert_response :success | |||||
| end | |||||
| test "should get edit" do | |||||
| get :edit | |||||
| assert_response :success | |||||
| end | |||||
| test "should get update" do | |||||
| get :update | |||||
| assert_response :success | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,12 @@ | |||||
| require 'test_helper' | |||||
| class UserMailerTest < ActionMailer::TestCase | |||||
| test "reset_password_email" do | |||||
| mail = UserMailer.reset_password_email | |||||
| assert_equal "Reset password email", mail.subject | |||||
| assert_equal ["to@example.org"], mail.to | |||||
| assert_equal ["from@example.com"], mail.from | |||||
| assert_match "Hi", mail.body.encoded | |||||
| end | |||||
| end | |||||
| @@ -0,0 +1,4 @@ | |||||
| require 'test_helper' | |||||
| class PasswordResetsHelperTest < ActionView::TestCase | |||||
| end | |||||