mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Starting a working forgot password system
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user