forked from SpinaCMS/Spina
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
246a8da
commit 12b0ba9
Showing
19 changed files
with
151 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Spina | ||
module Admin | ||
class PasswordResetsController < AdminController | ||
layout "spina/login" | ||
|
||
skip_before_action :authorize_user | ||
|
||
def new | ||
end | ||
|
||
def create | ||
user = User.find_by(email: params[:email]) | ||
|
||
if user.present? | ||
user.regenerate_password_reset_token | ||
user.update_attributes!(password_reset_sent_at: Time.zone.now) | ||
UserMailer.forgot_password(user).deliver_now | ||
redirect_to admin_login_path, flash: {success: t('spina.forgot_password.instructions_sent')} | ||
else | ||
flash.now[:alert] = t('spina.forgot_password.unknown_user') | ||
render :new | ||
end | ||
end | ||
|
||
def edit | ||
@user = User.find_by!(password_reset_token: params[:id]) | ||
end | ||
|
||
def update | ||
@user = User.find_by(password_reset_token: params[:id]) | ||
|
||
if @user.password_reset_sent_at < 2.hours.ago | ||
redirect_to new_admin_password_reset_path, flash: {alert: t('spina.forgot_password.expired')} | ||
elsif @user.update_attributes(user_params) | ||
redirect_to admin_login_path, flash: {success: t('spina.forgot_password.success')} | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:password, :password_confirmation) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Spina | ||
class UserMailer < ActionMailer::Base | ||
layout 'spina/mail' | ||
|
||
def forgot_password(user) | ||
@user = user | ||
|
||
mail( | ||
to: @user.email, | ||
from: current_account.email, | ||
subject: t('spina.forgot_password.mail_subject') | ||
) | ||
end | ||
|
||
private | ||
|
||
def current_account | ||
Spina::Account.first | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= yield %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
= form_for @user, url: spina.admin_password_reset_path(params[:id]), html: {id: "login_wrapper"} do |f| | ||
= image_tag 'spina/admin/spina.png', class: 'animated fadeInDown' | ||
- if @user.errors.any? | ||
.failed-to-login.animated.fadeInDown | ||
.icon.icon-cross | ||
= @user.errors.full_messages.join('<br />').html_safe | ||
|
||
.login-fields | ||
= f.text_field :password, placeholder: Spina::User.human_attribute_name(:password), autofocus: true, class: "animated fadeInDown" | ||
|
||
= f.text_field :password_confirmation, placeholder: Spina::User.human_attribute_name(:password_confirmation), class: "animated fadeInDown" | ||
|
||
= f.button t('spina.forgot_password.save'), class: 'button button-primary animated fadeInDown' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
= form_tag spina.admin_password_resets_path, method: :post, id: "login_wrapper" do | ||
= image_tag 'spina/admin/spina.png' | ||
- if flash[:alert].present? | ||
.failed-to-login.animated.fadeInDown | ||
.icon.icon-cross | ||
= flash[:alert] | ||
|
||
.login-fields | ||
= text_field_tag :email, params[:email], placeholder: Spina::User.human_attribute_name(:email), autofocus: true | ||
|
||
= button_tag t('spina.forgot_password.request'), class: 'button button-primary' | ||
|
||
.login-extra-links= link_to t('spina.login'), spina.admin_login_path, class: 'button button-hollow button-block' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You forgot your password dummy. Here's a link to setup a new one: <%= link_to 'Reset password', spina.edit_admin_password_reset_url(@user.password_reset_token) %>. It expires in 2 hours. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You forgot your password dummy. Here's a link to setup a new one: <%= spina.edit_admin_password_reset_url(@user.password_reset_token) %>. It expires in 2 hours. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddPasswordResetTokenToSpinaUsers < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :spina_users, :password_reset_token, :string | ||
add_column :spina_users, :password_reset_sent_at, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/dummy/db/migrate/20170507153143_add_password_reset_token_to_spina_users.spina.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This migration comes from spina (originally 4) | ||
class AddPasswordResetTokenToSpinaUsers < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :spina_users, :password_reset_token, :string | ||
add_column :spina_users, :password_reset_sent_at, :datetime | ||
end | ||
end |
Oops, something went wrong.