Starting a working forgot password system

This commit is contained in:
Will Marshall
2014-03-27 15:11:11 +11:00
parent adcd5e1c8d
commit e48a25983a
6 changed files with 61 additions and 4 deletions

View File

@@ -1,6 +1,21 @@
window.ForgotSidebarCtrl = Darkswarm.controller "ForgotSidebarCtrl", ($scope, $http, $location) ->
$scope.spree_user = {
email: null
}
$scope.active = ->
$location.path() == '/forgot'
$scope.select = ->
$location.path("/forgot")
$scope.submit = ->
if $scope.spree_user.email != null
$http.post("/user/spree_user/password", {spree_user: $scope.spree_user}).success (data)->
$location.path("/reset")
.error (data) ->
$scope.errors = "Email address not found"
else
$scope.errors = "You must provide an email address"

View File

@@ -1,3 +1,20 @@
class UserPasswordsController < Spree::UserPasswordsController
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if resource.errors.empty?
set_flash_message(:notice, :send_instructions) if is_navigational_format?
respond_with resource, :location => spree.login_path
else
respond_to do |format|
format.html do
respond_with_navigational(resource) { render :new }
end
format.js do
render json: resource.errors, status: :unauthorized
end
end
end
end
end

View File

@@ -2,4 +2,21 @@
heading: "Forgot Password?",
active: "active()",
select: "select()"}
Well you're a bit stupid then
{{ spree_user.email }}
%form{"ng-submit" => "submit()"}
.alert-box.alert{"ng-show" => "errors != null"}
{{ errors }}
.row
.large-12.columns
%label{for: "email"} Email
%input.title.input-text{name: "email",
type: "email",
tabindex: 1,
"ng-model" => "spree_user.email"}
.row
.large-12.columns
%input.button.primary{name: "commit",
tabindex: "3",
type: "submit",
value: "Reset password"}

View File

@@ -30,6 +30,7 @@ Openfoodnetwork::Application.configure do
# Show emails using Letter Opener
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { host: "test.com" }
end

View File

@@ -75,7 +75,7 @@ Spree::Core::Engine.routes.draw do
:class_name => 'Spree::User',
:controllers => { :sessions => 'spree/user_sessions',
:registrations => 'user_registrations',
:passwords => 'spree/user_passwords' },
:passwords => 'user_passwords' },
:skip => [:unlocks, :omniauth_callbacks],
:path_names => { :sign_out => 'logout' },
:path_prefix => :user

View File

@@ -8,7 +8,7 @@ describe UserPasswordsController do
ActionMailer::Base.default_url_options[:host] = "test.host"
end
it "returns errors when no data received" do
it "returns errors" do
spree_post :create, spree_user: {}
response.should be_success
response.should render_template "spree/user_passwords/new"
@@ -20,5 +20,12 @@ describe UserPasswordsController do
response.should be_redirect
end
describe "via ajax" do
it "returns errors" do
xhr :post, :create, spree_user: {}, use_route: :spree
json = JSON.parse(response.body)
response.status.should == 401
json.should == {"email"=>["can't be blank"]}
end
end
end