reset password mechanism added
This commit is contained in:
parent
a92475913a
commit
3175ad1d68
|
@ -57,6 +57,40 @@ class PseudoMembersController < PseudoSessionController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forgot
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
def resetsuccess
|
||||||
|
{}
|
||||||
|
end
|
||||||
|
|
||||||
|
def forgot_pseudo_user
|
||||||
|
puser = PseudoUser.where(:email => params[:email]).first
|
||||||
|
page_url = "/" + I18n.locale.to_s + Page.where(:module => "pseudo_member").first.url
|
||||||
|
if !puser.nil?
|
||||||
|
puser.generate_reset_token("http://#{request.host_with_port}#{page_url}?method=confirm_reset_email")
|
||||||
|
redirect_to page_url + "?method=resetsuccess"
|
||||||
|
else
|
||||||
|
redirect_to page_url + "?method=resetfail"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def confirm_reset_email
|
||||||
|
puser = PseudoUser.where(:reset_token => OrbitHelper.params[:reset_token]).first
|
||||||
|
{
|
||||||
|
"puser" => puser
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_pseudo_user
|
||||||
|
puser = PseudoUser.find(params[:puser_id])
|
||||||
|
page_url = "/" + I18n.locale.to_s + Page.where(:module => "pseudo_member").first.url
|
||||||
|
puser.update_password(params[:pseudo_user][:password],params[:pseudo_user][:password_confirmation])
|
||||||
|
redirect_to page_url + "?method=resetsuccessful"
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
# def login
|
# def login
|
||||||
# if !current_pseudo_user.nil?
|
# if !current_pseudo_user.nil?
|
||||||
# redirect_to member_dash_path(current_pseudo_user.account)
|
# redirect_to member_dash_path(current_pseudo_user.account)
|
||||||
|
|
|
@ -35,6 +35,22 @@ class PseudoUser
|
||||||
email.deliver
|
email.deliver
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_reset_token(url)
|
||||||
|
self.reset_token = SecureRandom.hex(5)
|
||||||
|
self.save
|
||||||
|
# PseudoMemberMailer.send_user_confirmation(self).deliver
|
||||||
|
email = Email.new
|
||||||
|
email.mail_to = self.email
|
||||||
|
email.mail_subject = "Click to reset your password."
|
||||||
|
email.template = "admin/pseudo_members/reset_password.html.erb"
|
||||||
|
email.template_data = {
|
||||||
|
"name" => self.name,
|
||||||
|
"url" => "#{url}&reset_token=#{self.reset_token}"
|
||||||
|
}
|
||||||
|
email.deliver
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def is_confirmed?
|
def is_confirmed?
|
||||||
self.confirmation_token.nil?
|
self.confirmation_token.nil?
|
||||||
end
|
end
|
||||||
|
@ -43,10 +59,10 @@ class PseudoUser
|
||||||
self.first_name + " " + self.last_name rescue self.email
|
self.first_name + " " + self.last_name rescue self.email
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_reset_token
|
# def generate_reset_token
|
||||||
self.reset_token = SecureRandom.hex(5)
|
# self.reset_token = SecureRandom.hex(5)
|
||||||
self.save
|
# self.save
|
||||||
end
|
# end
|
||||||
|
|
||||||
def self.check_password_token(reset_token = nil)
|
def self.check_password_token(reset_token = nil)
|
||||||
user = self.find_by(reset_token: reset_token) rescue nil
|
user = self.find_by(reset_token: reset_token) rescue nil
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<h3>Hello, <%= @data["name"] %></h3>
|
||||||
|
<p>
|
||||||
|
Please click on the link below to confirm your email address.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<a href="<%= @data["url"] %>">Confirm Email</a>
|
||||||
|
</p>
|
|
@ -0,0 +1,24 @@
|
||||||
|
<% data = action_data %>
|
||||||
|
<%= form_for data["puser"], :url => update_pseudo_user_path, html: {class: "form-horizontal"} do |f|%>
|
||||||
|
<h3>Confirm Password</h3>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label muted"><%= t("pseudo_member.password") %></label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<%= f.password_field :password %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label muted"><%= t("pseudo_member.password_confirmation") %></label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<%= f.password_field :password_confirmation %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-8">
|
||||||
|
<input type="hidden" value="<%= data["puser"].id.to_s %>" name="puser_id" />
|
||||||
|
<input type="submit" value="Register" class="btn btn-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<form method="post" action="<%= forgot_pseudo_user_path %>" class="form-horizontal">
|
||||||
|
<h3>Forgot Password</h3>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="col-sm-2 control-label muted"><%= t("pseudo_member.email") %></label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<input type="text" name="email" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-8">
|
||||||
|
<input type="submit" value="Submit" class="btn btn-primary">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
|
@ -29,4 +29,9 @@
|
||||||
<a href="<%= "/" + I18n.locale.to_s + OrbitHelper.params[:url] + "?method=register" %>" class="register-btn btn btn-info">Register</a>
|
<a href="<%= "/" + I18n.locale.to_s + OrbitHelper.params[:url] + "?method=register" %>" class="register-btn btn btn-info">Register</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-sm-offset-2 col-sm-8">
|
||||||
|
<a href="<%= "/" + I18n.locale.to_s + OrbitHelper.params[:url] + "?method=forgot" %>">Forgot Password?</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
<div class="alert alert-danger" role="alert">No user found with this email.</div>
|
|
@ -0,0 +1 @@
|
||||||
|
<div class="alert alert-success" role="alert">Reset Successful, Please check your email.</div>
|
|
@ -0,0 +1 @@
|
||||||
|
<div class="alert alert-success" role="alert">Reset Successful, password has been reset successfully.</div>
|
|
@ -16,6 +16,8 @@ Rails.application.routes.draw do
|
||||||
post "/loginpseudouser", to: "pseudo_members#loginuser"
|
post "/loginpseudouser", to: "pseudo_members#loginuser"
|
||||||
get "/logoutpseudouser", to: "pseudo_members#logoutuser", as: "member_logout"
|
get "/logoutpseudouser", to: "pseudo_members#logoutuser", as: "member_logout"
|
||||||
post "/register_pseudo_user", to: "pseudo_members#register_user", as: "register_pseudo_user"
|
post "/register_pseudo_user", to: "pseudo_members#register_user", as: "register_pseudo_user"
|
||||||
|
post "/forgot_pseudo_user", to: "pseudo_members#forgot_pseudo_user", as: "forgot_pseudo_user"
|
||||||
|
patch "/update_pseudo_user", to: "pseudo_members#update_pseudo_user", as: "update_pseudo_user"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue