fixing functional tests
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class LoginRemindersController < ApplicationController
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = ::User.with_email(params[:user][:email]).first
|
||||
if @user
|
||||
LoginReminderMailer.notice(@user).deliver
|
||||
flash[:notice] = "Email sent"
|
||||
else
|
||||
flash[:notice] = "Email address not found"
|
||||
end
|
||||
|
||||
redirect_to new_maintenance_user_login_reminder_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class PasswordResetsController < ApplicationController
|
||||
def new
|
||||
@nonce = UserPasswordResetNonce.new
|
||||
end
|
||||
|
||||
def create
|
||||
@nonce = UserPasswordResetNonce.create(params[:nonce])
|
||||
if @nonce.errors.any?
|
||||
redirect_to new_maintenance_user_password_reset_path, :notice => @nonce.errors.full_messages.join("; ")
|
||||
else
|
||||
redirect_to new_maintenance_user_password_reset_path, :notice => "Email request sent"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@nonce = UserPasswordResetNonce.where(:email => params[:email], :key => params[:key]).first
|
||||
end
|
||||
|
||||
def update
|
||||
@nonce = UserPasswordResetNonce.where(:email => params[:email], :key => params[:key]).first
|
||||
|
||||
if @nonce
|
||||
@nonce.reset_user!
|
||||
@nonce.destroy
|
||||
redirect_to new_maintenance_user_password_reset_path, :notice => "Password reset; email delivered with new password"
|
||||
else
|
||||
redirect_to new_maintenance_user_password_reset_path, :notice => "Invalid key"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,25 +0,0 @@
|
||||
class UserMaintenanceController < ApplicationController
|
||||
def login_reminder
|
||||
if request.post?
|
||||
@user = User.with_email(params[:user][:email]).first
|
||||
if @user
|
||||
UserMaintenanceMailer.login_reminder(@user).deliver
|
||||
flash[:notice] = "Email sent"
|
||||
else
|
||||
flash[:notice] = "No matching user record found"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reset_password
|
||||
if request.post?
|
||||
@user = User.find_for_password_reset(params[:user][:name], params[:user][:email]).first
|
||||
if @user
|
||||
@user.reset_password_and_deliver_notice
|
||||
flash[:notice] = "Email sent"
|
||||
else
|
||||
flash[:notice] = "No matching user record found"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,7 +3,7 @@ class WikiPageVersionsController < ApplicationController
|
||||
|
||||
def index
|
||||
@search = WikiPageVersion.search(params[:search])
|
||||
@wiki_page_versions = @search.paginate(:page => params[:page])
|
||||
@wiki_page_versions = @search.paginate(params[:page])
|
||||
respond_with(@wiki_page_versions)
|
||||
end
|
||||
|
||||
|
||||
@@ -6,5 +6,13 @@ module PostSets
|
||||
super(:tags => artist.name)
|
||||
@artist = artist
|
||||
end
|
||||
|
||||
def posts
|
||||
::Post.tag_match(@artist.name)
|
||||
end
|
||||
|
||||
def presenter
|
||||
::PostSetPresenters::Post.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
10
app/mailers/maintenance/user/login_reminder_mailer.rb
Normal file
10
app/mailers/maintenance/user/login_reminder_mailer.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class LoginReminderMailer < ActionMailer::Base
|
||||
def notice(user)
|
||||
@user = user
|
||||
mail(:to => user.email, :subject => "#{Danbooru.config.app_name} login reminder")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
15
app/mailers/maintenance/user/password_reset_mailer.rb
Normal file
15
app/mailers/maintenance/user/password_reset_mailer.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
module Maintenance
|
||||
module User
|
||||
class PasswordResetMailer < ActionMailer::Base
|
||||
def request(user)
|
||||
@user = user
|
||||
mail(:to => @user.email, :subject => "#{Danbooru.config.app_name} password reset request")
|
||||
end
|
||||
|
||||
def confirmation(user)
|
||||
@user = user
|
||||
mail(:to => @user.email, :subject => "#{Danbooru.config.app_name} password reset confirmation")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,10 +1,6 @@
|
||||
class UserMaintenanceMailer < ActionMailer::Base
|
||||
default :from => Danbooru.config.contact_email
|
||||
|
||||
def login_reminder(user)
|
||||
@user = user
|
||||
mail(:to => user.email, :subject => "#{Danbooru.config.app_name} login reminder")
|
||||
end
|
||||
|
||||
def reset_password(user, new_password)
|
||||
@user = user
|
||||
|
||||
30
app/models/user_password_reset_nonce.rb
Normal file
30
app/models/user_password_reset_nonce.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
class UserPasswordResetNonce < ActiveRecord::Base
|
||||
validates_uniqueness_of :email
|
||||
validates_presence_of :email, :key
|
||||
validate :validate_existence_of_email
|
||||
before_validation :initialize_key, :on => :create
|
||||
after_create :deliver_notice
|
||||
|
||||
def deliver_notice
|
||||
Maintenance::User::PasswordResetMailer.request(user).deliver
|
||||
end
|
||||
|
||||
def initialize_key
|
||||
self.key = SecureRandom.hex(16)
|
||||
end
|
||||
|
||||
def validate_existence_of_email
|
||||
if !User.with_email(email).exists?
|
||||
errors[:email] << "is invalid"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user!
|
||||
user.reset_password_and_deliver_notice
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= User.with_email(email).first
|
||||
end
|
||||
end
|
||||
@@ -82,7 +82,7 @@ class WikiPage < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def post_set
|
||||
@post_set ||= PostSets::WikiPage.new(title)
|
||||
@post_set ||= PostSets::Post.new(title)
|
||||
end
|
||||
|
||||
def presenter
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<p>Your username is <%= @user.name %>.</p>
|
||||
9
app/views/maintenance/user/login_reminders/new.html.erb
Normal file
9
app/views/maintenance/user/login_reminders/new.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<div id="c-maintenance-user-login-reminders">
|
||||
<div id="a-new">
|
||||
<h1>Login Reminder</h1>
|
||||
|
||||
<p>If you supplied an email address when signing up, <%= Danbooru.config.app_name %> can email you your login information. Password details will not be provided and will not be changed.</p>
|
||||
|
||||
<p>If you didn't supply a valid email address, you are out of luck.</p>
|
||||
</div>
|
||||
</div>
|
||||
14
app/views/maintenance/user/password_resets/edit.html.erb
Normal file
14
app/views/maintenance/user/password_resets/edit.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<div id="c-maintenance-user-password-resets">
|
||||
<div id="a-edit">
|
||||
<h1>Reset Password</h1>
|
||||
|
||||
<% if @nonce %>
|
||||
<%= form_tag(maintenance_user_password_reset_path, :method => :put) do %>
|
||||
<p>Do you wish to reset your password? A new password will be emailed to you.</p>
|
||||
<%= submit_tag "Reset" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<p>Invalid key</p>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
14
app/views/maintenance/user/password_resets/new.html.erb
Normal file
14
app/views/maintenance/user/password_resets/new.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<div id="c-maintenance-user-password-resets">
|
||||
<div id="a-new">
|
||||
<h1>Reset Password</h1>
|
||||
|
||||
<p>If you supplied an email address when signing up, <%= Danbooru.config.app_name %> can reset your password. You will receive an email confirming your request for a new password.</p>
|
||||
|
||||
<p>If you didn't supply a valid email address, you are out of luck.</p>
|
||||
|
||||
<%= form_tag(maintenance_user_password_reset_path, :method => :post) do %>
|
||||
<%= text_field :nonce, :email %>
|
||||
<%= submit_tag "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -4,12 +4,6 @@
|
||||
|
||||
<% simple_form_for(@search) do |f| %>
|
||||
<%= f.input :name_contains, :label => "Name" %>
|
||||
<%= f.input :is_banned_is_true, :label => "Banned" %>
|
||||
<%= f.input :is_privileged_is_true, :label => "Privileged" %>
|
||||
<%= f.input :is_contributor_is_true, :label => "Contributor" %>
|
||||
<%= f.input :is_janitor_is_true, :label => "Janitor" %>
|
||||
<%= f.input :is_moderator_is_true, :label => "Moderator" %>
|
||||
<%= f.input :is_admin_is_true, :label => "Admin" %>
|
||||
<%= f.sort_link "Name", :name %>
|
||||
<%= f.sort_link "Date", :created_at_desc %>
|
||||
<%= f.button :submit %>
|
||||
@@ -47,18 +41,18 @@
|
||||
<td></td>
|
||||
<% end %>
|
||||
<td><%= link_to user.note_versions.count, note_versions_path(:search => {:updater_id_eq => user.id}) %></td>
|
||||
<td><%= user.pretty_level %></td>
|
||||
<td><%= user.level_string %></td>
|
||||
<td><span title="<%= user.created_at %>"><%= time_ago_in_words user.created_at %> ago</span></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div id="paginator">
|
||||
<%= will_paginate(@users) %>
|
||||
<div class="paginator">
|
||||
<%= numbered_paginator(@users) %>
|
||||
</div>
|
||||
|
||||
<%= render :partial => "footer" %>
|
||||
<%= render "secondary_links" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
|
||||
<div id="wiki-page-posts">
|
||||
<%= @wiki_page.post_set.presenter.post_previews_html %>
|
||||
<%= @wiki_page.post_set.presenter.post_previews_html(self) %>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user