Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

http_basic and reset_password work

  • Loading branch information...
commit 91757460849418b9b1d26b32ae56a97d7f8077ff 1 parent 964a6f5
@NoamB authored
Showing with 21 additions and 18 deletions.
  1. BIN  dummy
  2. +11 −7 myapp.rb
  3. +10 −11 views/password_resets/_form.erb
View
BIN  dummy
Binary file not shown
View
18 myapp.rb
@@ -33,6 +33,9 @@
# models
require 'sorcery'
Sorcery::Controller::Config.submodules = [:user_activation, :http_basic_auth, :remember_me, :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :oauth]
+include Sorcery::Controller::Adapters::Sinatra
+include Sorcery::Controller
+
Sinatra::Application.activate_sorcery! do |config|
config.session_timeout = 10.minutes
config.session_timeout_from_last_action = false
@@ -61,7 +64,7 @@
end
end
-before '/test_http_basic_auth' do
+before '/login/http' do
require_login_from_http_basic
end
@@ -77,6 +80,10 @@
def current_users_list
current_users.map {|u| u.email}.join(", ")
end
+
+ def not_authenticated
+ halt "You must login to see this page!"
+ end
end
# actions
@@ -150,9 +157,10 @@ def current_users_list
@user = User.load_from_reset_password_token(params[:token])
@token = params[:token]
not_authenticated if !@user
+ erb :'password_resets/edit'
end
-put '/password_resets' do
+put '/password_resets/:id' do
@user = User.load_from_reset_password_token(params[:token])
not_authenticated if !@user
# the next line clears the temporary token and updates the password
@@ -164,12 +172,8 @@ def current_users_list
end
end
-def not_authenticated
- halt "You must login to see this page!"
-end
-
# HTTP Basic Auth
-get '/login_with_http_basic_auth' do
+get '/login/http' do
erb "HTTP Basic Auth"
end
View
21 views/password_resets/_form.erb
@@ -1,4 +1,4 @@
-<%= form_for @user, :url => password_reset_path(@user), :html => {:method => :put} do |f| %>
+<form accept-charset="UTF-8" action="/password_resets/<%= @user.id %>" id="edit_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
@@ -10,21 +10,20 @@
</ul>
</div>
<% end %>
-
<div class="field">
- <%= f.label :email %><br />
- <%= @user.email %>
+ <label for="user_email">Email</label><br />
+ <%= @user.email %>
</div>
<div class="field">
- <%= f.label :password %><br />
- <%= f.password_field :password %>
+ <label for="user_password">Password</label><br />
+ <input id="user_password" name="user[password]" size="30" type="password" />
</div>
<div class="field">
- <%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %>
- <%= hidden_field_tag :token, @token %>
+ <label for="user_password_confirmation">Password confirmation</label><br />
+ <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
+ <input id="token" name="token" type="hidden" value="<%= @user.reset_password_token %>" />
</div>
<div class="actions">
- <%= f.submit %>
+ <input id="user_submit" name="commit" type="submit" value="Update User" />
</div>
-<% end %>
+</form>
Please sign in to comment.
Something went wrong with that request. Please try again.