Sha256: b53b63f6a4a60c83da26ef400310f82ebb2eb7c835de09e2f51a99c9caa504fa
Contents?: true
Size: 1.82 KB
Versions: 4
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal class <%= plural_class_name %>::PasswordResetsController < <%= plural_class_name %>::BaseController skip_before_action :authenticate_<%= singular_name %> def new end def create @<%= singular_name %> = <%= plural_name %>_scope.find_by(email: permitted_params[:email]) if @<%= singular_name %> @<%= singular_name %>.create_password_reset_token <%= class_name %>Mailer.password_reset_link(@<%= singular_name %>).deliver_later end redirect_to new_<%= plural_name %>_session_url, notice: "Please check your email for a password reset link" end def edit @<%= singular_name %> = find_<%= singular_name %>_from_token(params[:token]) if @<%= singular_name %>.nil? or @<%= singular_name %>.password_reset_token.expired? redirect_to new_<%= plural_name %>_session_url, error: "The link you followed does not look valid" end end def update @<%= singular_name %> = find_<%= singular_name %>_from_token(params[:token]) if @<%= singular_name %>.update(password: permitted_params[:password], password_confirmation: permitted_params[:password_confirmation]) @<%= singular_name %>.destroy_password_reset_token redirect_to new_<%= plural_name %>_session_url, notice: "Successfully reset your password" else render :edit end end private def permitted_params params.require(:<%= singular_name %>).permit(:email, :password, :password_confirmation) end # Change me to suit the scoping requirements for this project def <%= plural_name %>_scope <%= class_name %>.all end def find_<%= singular_name %>_from_token(token) <%= plural_name %>_scope.joins(:password_reset_token) .where(password_reset_tokens: { secret: params[:token] }).first end end
Version data entries
4 entries across 4 versions & 1 rubygems