adds user/admin profile and user mailers
Merge branch 'feature/71-user-profile-admin' into develop
This commit is contained in:
commit
2f61d58bba
@ -25,6 +25,16 @@
|
||||
background-color: #f39c12;
|
||||
}
|
||||
|
||||
.success {
|
||||
@extend .error;
|
||||
background-color: $brand-success;
|
||||
}
|
||||
|
||||
.notice {
|
||||
@extend .error;
|
||||
background-color: $brand-info;
|
||||
}
|
||||
|
||||
[data-id="live-coder-finish-later"] {
|
||||
.warning {
|
||||
margin-top: 0;
|
||||
|
@ -21,5 +21,44 @@ module Admin
|
||||
reset_session
|
||||
redirect_to admin_login_path
|
||||
end
|
||||
|
||||
def reset_request
|
||||
end
|
||||
|
||||
def send_reset
|
||||
user = User.find_by(email: request_params[:email])
|
||||
redirect_to(admin_reset_request_path) and return if user.nil?
|
||||
|
||||
user.setup_reset
|
||||
UserMailer.password_reset(user).deliver_now
|
||||
redirect_to admin_reset_request_path,
|
||||
success: "Reset request sent! Please check your email for instructions."
|
||||
end
|
||||
|
||||
def reset
|
||||
user = User.find_by(reset_token: params[:reset_token])
|
||||
redirect_to(admin_reset_request_path) and return if user.nil?
|
||||
end
|
||||
|
||||
def reset_password
|
||||
user = User.find_by(reset_token: params[:reset_token])
|
||||
redirect_to(admin_reset_request_path) and return if user.nil?
|
||||
|
||||
if user.update(reset_params)
|
||||
redirect_to admin_login_path, success: "Password has been reset. Please log in."
|
||||
else
|
||||
redirect_to admin_reset_request_path, flash: { error: "Password was not updated." }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def request_params
|
||||
params.require(:auth).permit(:email)
|
||||
end
|
||||
|
||||
def reset_params
|
||||
params.require(:auth).permit(:password, :password_confirmation)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
28
app/controllers/admin/profile_controller.rb
Normal file
28
app/controllers/admin/profile_controller.rb
Normal file
@ -0,0 +1,28 @@
|
||||
module Admin
|
||||
class ProfileController < AdminController
|
||||
def view
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = current_admin
|
||||
end
|
||||
|
||||
def update
|
||||
@user = current_admin
|
||||
|
||||
if @user.update_attributes(user_params)
|
||||
redirect_to admin_profile_path,
|
||||
flash: { success: "Sucessfully updated profile" }
|
||||
else
|
||||
flash[:error] = "Failed to update profile."
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email, :password, :password_confirmation)
|
||||
end
|
||||
end
|
||||
end
|
@ -14,7 +14,7 @@ module Admin
|
||||
@question = Question.create(process_question_params)
|
||||
|
||||
if @question.persisted?
|
||||
redirect_to admin_questions_path, flash: { notice: "Sucessfully created question" }
|
||||
redirect_to admin_questions_path, flash: { success: "Sucessfully created question" }
|
||||
else
|
||||
flash[:error] = "Failed to save question."
|
||||
render :new
|
||||
@ -36,7 +36,7 @@ module Admin
|
||||
|
||||
if @question.update_attributes(process_question_params)
|
||||
redirect_to admin_question_path(@question.to_i),
|
||||
flash: { notice: "Sucessfully updated question" }
|
||||
flash: { success: "Sucessfully updated question" }
|
||||
else
|
||||
flash[:error] = "Failed to update question."
|
||||
render :edit
|
||||
|
@ -13,8 +13,8 @@ module Admin
|
||||
@user = User.create({ password: default_passwd }.merge(user_params.to_h))
|
||||
|
||||
if @user.persisted?
|
||||
# TODO: UserMailer.welcome(@user, default_passwd).deliver_now
|
||||
redirect_to admin_users_path, flash: { notice: "Sucessfully created user #{@user.name}" }
|
||||
UserMailer.welcome(@user, default_passwd).deliver_now
|
||||
redirect_to admin_users_path, flash: { success: "Sucessfully created user #{@user.name}" }
|
||||
else
|
||||
flash[:error] = "Failed to save user."
|
||||
render :new
|
||||
@ -34,7 +34,7 @@ module Admin
|
||||
|
||||
if @user.update_attributes(user_params)
|
||||
redirect_to admin_user_path(@user.to_i),
|
||||
flash: { notice: "Sucessfully updated #{@user.name}" }
|
||||
flash: { success: "Sucessfully updated #{@user.name}" }
|
||||
else
|
||||
flash[:error] = "Failed to update user."
|
||||
render :edit
|
||||
|
@ -1,6 +1,6 @@
|
||||
class AdminController < ApplicationController
|
||||
layout 'admin'
|
||||
before_action :authorize_admin, except: :styleguide
|
||||
before_action :authorize_admin
|
||||
|
||||
def dashboard
|
||||
@quizzes = Quiz.includes(:questions).all
|
||||
|
@ -1,6 +1,8 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
add_flash_types :warning, :success
|
||||
|
||||
def current_recruiter
|
||||
user_parms = { id: session[:user], role: %w(admin recruiter) }
|
||||
@current_recruiter ||= User.find_by(user_parms) if session[:user]
|
||||
|
@ -16,7 +16,7 @@ class RecruiterController < ApplicationController
|
||||
if @candidate.persisted?
|
||||
CandidateMailer.welcome(@candidate).deliver_now
|
||||
RecruiterMailer.candidate_created(@candidate).deliver_now
|
||||
redirect_to recruiter_path, flash: { notice: "Sucessfully created candidate #{@candidate.name}" }
|
||||
redirect_to recruiter_path, flash: { success: "Sucessfully created candidate #{@candidate.name}" }
|
||||
else
|
||||
flash[:error] = "Failed to save candidate."
|
||||
render :form
|
||||
|
12
app/mailers/user_mailer.rb
Normal file
12
app/mailers/user_mailer.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class UserMailer < ApplicationMailer
|
||||
def password_reset user
|
||||
@user = user
|
||||
mail to: user.email, subject: 'Password Reset'
|
||||
end
|
||||
|
||||
def welcome user, default_password
|
||||
@user = user
|
||||
@password = default_password
|
||||
mail to: user.email, subject: "Skill Assesment Acount"
|
||||
end
|
||||
end
|
@ -5,4 +5,20 @@ class User < ApplicationRecord
|
||||
validates_presence_of :email
|
||||
validates_presence_of :name
|
||||
validates_presence_of :role
|
||||
validates :reset_token, uniqueness: true, allow_nil: true
|
||||
|
||||
def setup_reset
|
||||
gen_reset_token
|
||||
save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def gen_reset_token
|
||||
loop do
|
||||
self[:reset_token] = SecureRandom.urlsafe_base64(10)
|
||||
self[:reset_timestamp] = DateTime.now
|
||||
break unless User.exists?(reset_token: self[:reset_token])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,21 +1,19 @@
|
||||
<main class="intro_tpl">
|
||||
<h1>Admin Login</h1>
|
||||
<%
|
||||
content_for :main_class, "intro_tpl"
|
||||
%>
|
||||
|
||||
<% if flash[:error].present? %>
|
||||
<div class="error"><%= flash[:error] %></div>
|
||||
<% end %>
|
||||
<h1>Admin Login</h1>
|
||||
|
||||
<%= form_for :auth, url: admin_login_path do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
<%= form_for :auth, url: admin_login_path do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password %>
|
||||
<%= form.password_field :password %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= form.label :password %>
|
||||
<%= form.password_field :password %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Log in" %>
|
||||
<% end %>
|
||||
</main>
|
||||
<%= submit_tag "Log in" %>
|
||||
<% end %>
|
||||
|
21
app/views/admin/auth/reset.html.erb
Normal file
21
app/views/admin/auth/reset.html.erb
Normal file
@ -0,0 +1,21 @@
|
||||
<%
|
||||
content_for :main_class, "intro_tpl"
|
||||
%>
|
||||
|
||||
<h1>Password Reset</h1>
|
||||
|
||||
<%= form_for :auth, url: admin_reset_password_path do |form| %>
|
||||
<%= hidden_field_tag :reset_token, params[:reset_token] %>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password %>
|
||||
<%= form.password_field :password %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password_confirmation %>
|
||||
<%= form.password_field :password_confirmation %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Reset Password" %>
|
||||
<% end %>
|
14
app/views/admin/auth/reset_request.html.erb
Normal file
14
app/views/admin/auth/reset_request.html.erb
Normal file
@ -0,0 +1,14 @@
|
||||
<%
|
||||
content_for :main_class, "intro_tpl"
|
||||
%>
|
||||
|
||||
<h1>Password Reset</h1>
|
||||
<%= form_for :auth, url: admin_send_reset_path do |form| %>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :email %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag "Request Password Reset" %>
|
||||
<% end %>
|
@ -2,17 +2,14 @@
|
||||
content_for :section_title, "Admin Dashboard"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<section>
|
||||
<h1>Quizzes</h1>
|
||||
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
|
||||
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
|
||||
</section>
|
||||
<section>
|
||||
<h1>Quizzes</h1>
|
||||
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
|
||||
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h1>Users</h1>
|
||||
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
|
||||
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
<section>
|
||||
<h1>Users</h1>
|
||||
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
|
||||
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
|
||||
</section>
|
||||
|
28
app/views/admin/profile/edit.html.erb
Normal file
28
app/views/admin/profile/edit.html.erb
Normal file
@ -0,0 +1,28 @@
|
||||
<%
|
||||
content_for :section_title, "Edit: #{@user.name}"
|
||||
%>
|
||||
|
||||
<%= render partial: 'shared/form_model_errors', locals: {obj: @user} %>
|
||||
<%= form_for @user, url: admin_profile_url, method: :post do |form| %>
|
||||
<div class="form-group">
|
||||
<%= form.label :name, "Full Name" %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :email, "eMail" %>
|
||||
<%= form.email_field :email %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password, "New Password" %>
|
||||
<%= form.password_field :password %>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<%= form.label :password_confirmation, "New Password Confirmation" %>
|
||||
<%= form.password_field :password_confirmation %>
|
||||
</div>
|
||||
|
||||
<%= form.submit %>
|
||||
<% end %>
|
8
app/views/admin/profile/view.html.erb
Normal file
8
app/views/admin/profile/view.html.erb
Normal file
@ -0,0 +1,8 @@
|
||||
<%
|
||||
content_for :section_title, "Profile"
|
||||
%>
|
||||
|
||||
<p>Name: <%= current_admin.name %></p>
|
||||
<p>email: <%= current_admin.email %></p>
|
||||
<p>Role: <%= current_admin.role %></p>
|
||||
<%= link_to('Edit', admin_edit_profile_path, { class: 'btn' }) %>
|
@ -2,8 +2,5 @@
|
||||
content_for :section_title, "Questions"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<h1><%= @question.quiz.name %></h1>
|
||||
|
||||
<%= render partial: 'form', locals: {question: @question, action: admin_update_question_path } %>
|
||||
</main>
|
||||
<h1><%= @question.quiz.name %></h1>
|
||||
<%= render partial: 'form', locals: {question: @question, action: admin_update_question_path } %>
|
||||
|
@ -2,11 +2,9 @@
|
||||
content_for :section_title, "Questions"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<% quizzes = @questions.group_by{ |q| q.quiz.name } %>
|
||||
<% quizzes.each do |quiz, questions| %>
|
||||
<h1><%= quiz %></h1>
|
||||
<%= render partial: 'admin/question/table_list', locals: { questions: questions } %>
|
||||
<%= link_to('Edit Quiz', admin_quiz_path(questions.first.quiz.to_i), { class: 'btn' }) %>
|
||||
<% end %>
|
||||
</main>
|
||||
<% quizzes = @questions.group_by{ |q| q.quiz.name } %>
|
||||
<% quizzes.each do |quiz, questions| %>
|
||||
<h1><%= quiz %></h1>
|
||||
<%= render partial: 'admin/question/table_list', locals: { questions: questions } %>
|
||||
<%= link_to('Edit Quiz', admin_quiz_path(questions.first.quiz.to_i), { class: 'btn' }) %>
|
||||
<% end %>
|
||||
|
@ -2,6 +2,4 @@
|
||||
content_for :section_title, "New Question"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<%= render partial: 'form', locals: {question: @question, action: admin_create_question_path } %>
|
||||
</main>
|
||||
<%= render partial: 'form', locals: {question: @question, action: admin_create_question_path } %>
|
||||
|
@ -2,37 +2,35 @@
|
||||
content_for :section_title, "Question for #{@question.quiz.name}"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<th>Category</th>
|
||||
<td><%= @question.category %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<td><%= @question.input_type %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Sort</th>
|
||||
<td><%= @question.sort %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<%= check_box_tag 'question_active', nil, @question.active?, {disabled: true} %>
|
||||
<%= label_tag 'question_active', 'Active' %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<th>Category</th>
|
||||
<td><%= @question.category %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Type</th>
|
||||
<td><%= @question.input_type %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Sort</th>
|
||||
<td><%= @question.sort %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td>
|
||||
<%= check_box_tag 'question_active', nil, @question.active?, {disabled: true} %>
|
||||
<%= label_tag 'question_active', 'Active' %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<strong>Question</strong>
|
||||
<p><%= @question.question %></p>
|
||||
<strong>Question</strong>
|
||||
<p><%= @question.question %></p>
|
||||
|
||||
<%= fields_for @question do |fields| %>
|
||||
<%= render partial: "admin/question/#{@question.input_type}", locals: {question: @question, disable: true, fields: fields } %>
|
||||
<% end %>
|
||||
<%= fields_for @question do |fields| %>
|
||||
<%= render partial: "admin/question/#{@question.input_type}", locals: {question: @question, disable: true, fields: fields } %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to('Edit', admin_edit_question_path(@question.to_i), { class: 'btn' }) %>
|
||||
<%= link_to('Edit', admin_edit_question_path(@question.to_i), { class: 'btn' }) %>
|
||||
|
||||
<%= link_to('View Quiz', admin_quiz_path(@question.quiz_id), { class: 'btn' }) %>
|
||||
</main>
|
||||
<%= link_to('View Quiz', admin_quiz_path(@question.quiz_id), { class: 'btn' }) %>
|
||||
|
@ -2,6 +2,4 @@
|
||||
content_for :section_title, "Edit: #{@quiz.name}"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %>
|
||||
</main>
|
||||
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_update_quiz_path } %>
|
||||
|
@ -2,7 +2,5 @@
|
||||
content_for :section_title, "Quizzes"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
|
||||
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
|
||||
</main>
|
||||
<%= render partial: 'admin/quiz/table_list', locals: { quizzes: @quizzes } %>
|
||||
<%= link_to('New Quiz', admin_new_quiz_path, { class: 'btn' }) %>
|
||||
|
@ -2,6 +2,4 @@
|
||||
content_for :section_title, "New Quiz"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %>
|
||||
</main>
|
||||
<%= render partial: 'form', locals: { quiz: @quiz, action: admin_create_quiz_path } %>
|
||||
|
@ -2,14 +2,10 @@
|
||||
content_for :section_title, "#{@quiz.name}"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<p><%= @quiz.name %></p>
|
||||
<p><%= @quiz.dept %></p>
|
||||
<p><%= @quiz.unit %></p>
|
||||
<%= link_to('Edit', admin_edit_quiz_path(@quiz.to_i), { class: 'btn' }) %>
|
||||
</main>
|
||||
<p><%= @quiz.name %></p>
|
||||
<p><%= @quiz.dept %></p>
|
||||
<p><%= @quiz.unit %></p>
|
||||
<%= link_to('Edit', admin_edit_quiz_path(@quiz.to_i), { class: 'btn' }) %>
|
||||
|
||||
<main class="summary_tpl">
|
||||
<%= render partial: 'admin/question/table_list', locals: { questions: @quiz.questions, disable: true } %>
|
||||
<%= link_to('New Question', admin_new_question_path, { class: 'btn' }) %>
|
||||
</main>
|
||||
<%= render partial: 'admin/question/table_list', locals: { questions: @quiz.questions, disable: true } %>
|
||||
<%= link_to('New Question', admin_new_question_path, { class: 'btn' }) %>
|
||||
|
@ -2,6 +2,4 @@
|
||||
content_for :section_title, "Edit: #{@user.name}"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %>
|
||||
</main>
|
||||
<%= render partial: 'form', locals: {user: @user, action: admin_update_user_path } %>
|
||||
|
@ -2,8 +2,6 @@
|
||||
content_for :section_title, "Users"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<h1>Users</h1>
|
||||
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
|
||||
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
|
||||
</main>
|
||||
<h1>Users</h1>
|
||||
<%= render partial: 'admin/user/table_list', locals: { users: @users } %>
|
||||
<%= link_to('New User', admin_new_user_path, { class: 'btn' }) %>
|
||||
|
@ -2,6 +2,4 @@
|
||||
content_for :section_title, "New User"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %>
|
||||
</main>
|
||||
<%= render partial: 'form', locals: {user: @user, action: admin_create_user_path } %>
|
||||
|
@ -2,9 +2,7 @@
|
||||
content_for :section_title, "#{@user.name}"
|
||||
%>
|
||||
|
||||
<main class="admin_tpl">
|
||||
<p><%= @user.name %></p>
|
||||
<p><%= mail_to(@user.email) %></p>
|
||||
<p><%= @user.role %></p>
|
||||
<%= link_to('Edit', admin_edit_user_path(@user.to_i), { class: 'btn' }) %>
|
||||
</main>
|
||||
<p><%= @user.name %></p>
|
||||
<p><%= mail_to(@user.email) %></p>
|
||||
<p><%= @user.role %></p>
|
||||
<%= link_to('Edit', admin_edit_user_path(@user.to_i), { class: 'btn' }) %>
|
||||
|
@ -8,8 +8,10 @@
|
||||
</p>
|
||||
<p>
|
||||
You can return to the test here:
|
||||
<%= link_to nil, root_url %>.
|
||||
<%= link_to nil, login_url(@candidate.test_hash) %>.
|
||||
<br />
|
||||
<br />
|
||||
Or, visit <%= link_to nil, root_url %> and enter your Test ID to complete your test.
|
||||
Your Test ID is: <strong><%= @candidate.test_hash %></strong>
|
||||
</p>
|
||||
</columns>
|
||||
|
@ -30,7 +30,10 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<%= yield %>
|
||||
<main class="<%= content_for?(:main_class) ? yield(:main_class) : "admin_tpl" %>">
|
||||
<%= render partial: "shared/generic_flash" %>
|
||||
<%= yield %>
|
||||
</main>
|
||||
|
||||
</div>
|
||||
|
||||
|
15
app/views/shared/_generic_flash.html.erb
Normal file
15
app/views/shared/_generic_flash.html.erb
Normal file
@ -0,0 +1,15 @@
|
||||
<% if flash[:error].present? %>
|
||||
<div class="error"><%= flash[:error] %></div>
|
||||
<% end %>
|
||||
|
||||
<% if flash[:success].present? %>
|
||||
<div class="success"><%= flash[:success] %></div>
|
||||
<% end %>
|
||||
|
||||
<% if flash[:warning].present? %>
|
||||
<div class="warning"><%= flash[:warning] %></div>
|
||||
<% end %>
|
||||
|
||||
<% if flash[:notice].present? %>
|
||||
<div class="notice"><%= flash[:notice] %></div>
|
||||
<% end %>
|
@ -150,7 +150,9 @@
|
||||
</div>
|
||||
|
||||
<div class="error">This is a sample error message.</div>
|
||||
|
||||
<div class="success">This is a sample success message.</div>
|
||||
<div class="warning">This is a sample warning message.</div>
|
||||
<div class="notice">This is a sample notice message.</div>
|
||||
|
||||
<hr>
|
||||
|
||||
|
13
app/views/user_mailer/password_reset.html.inky
Normal file
13
app/views/user_mailer/password_reset.html.inky
Normal file
@ -0,0 +1,13 @@
|
||||
<row>
|
||||
<columns class="email-body">
|
||||
<p>Hey there <%= @user.name %>,</p>
|
||||
<p>
|
||||
It looks like you want to reset your password?
|
||||
If not, it is safe to ignore this email.
|
||||
Otherwise go to the following link to enter a new password.
|
||||
</p>
|
||||
<p>
|
||||
<%= link_to nil, admin_reset_url(reset_token: @user.reset_token) %>.
|
||||
</p>
|
||||
</columns>
|
||||
</row>
|
7
app/views/user_mailer/password_reset.text.erb
Normal file
7
app/views/user_mailer/password_reset.text.erb
Normal file
@ -0,0 +1,7 @@
|
||||
Hey there <%= @user.name %>,
|
||||
|
||||
It looks like you want to reset your password?
|
||||
If not, it is safe to ignore this email.
|
||||
Otherwise go to the following link to enter a new password:
|
||||
|
||||
<%= admin_reset_url(reset_token: @user.reset_token) %>
|
15
app/views/user_mailer/welcome.html.inky
Normal file
15
app/views/user_mailer/welcome.html.inky
Normal file
@ -0,0 +1,15 @@
|
||||
<row>
|
||||
<columns class="email-body">
|
||||
<p>Hey there <%= @user.name %>,</p>
|
||||
<p>
|
||||
Looks like you now have access to the skills assessment app.
|
||||
We've given you a temporary password below. Please sign in an personalize it asap.
|
||||
</p>
|
||||
<p>
|
||||
Password: <%= @password%>
|
||||
</p>
|
||||
<p>
|
||||
<%= link_to nil, admin_url %>.
|
||||
</p>
|
||||
</columns>
|
||||
</row>
|
8
app/views/user_mailer/welcome.text.erb
Normal file
8
app/views/user_mailer/welcome.text.erb
Normal file
@ -0,0 +1,8 @@
|
||||
Hey there <%= @user.name %>,
|
||||
|
||||
Looks like you now have access to the skills assessment app.
|
||||
We've given you a temporary password below. Please sign in an personalize it asap.
|
||||
|
||||
Password: <%= @password %>
|
||||
|
||||
<%= admin_url %>.
|
@ -1,9 +1,11 @@
|
||||
Rails.application.routes.draw do
|
||||
post "/admin/login", to: "admin/auth#auth", as: :admin_auth
|
||||
get "/admin/login", to: "admin/auth#login", as: :admin_login
|
||||
get "/admin/logout", to: "admin/auth#logout", as: :admin_logout
|
||||
|
||||
get "/admin", to: "admin#dashboard", as: :admin
|
||||
post "/admin/login", to: "admin/auth#auth", as: :admin_auth
|
||||
get "/admin/login", to: "admin/auth#login", as: :admin_login
|
||||
get "/admin/logout", to: "admin/auth#logout", as: :admin_logout
|
||||
get "/admin/reset/:reset_token", to: "admin/auth#reset", as: :admin_reset
|
||||
post "/admin/reset", to: "admin/auth#reset_password", as: :admin_reset_password
|
||||
get "/admin/reset_request", to: "admin/auth#reset_request", as: :admin_reset_request
|
||||
post "/admin/reset_request", to: "admin/auth#send_reset", as: :admin_send_reset
|
||||
|
||||
get "/admin/quizzes", to: "admin/quiz#index", as: :admin_quizzes
|
||||
get "/admin/quiz/new", to: "admin/quiz#new", as: :admin_new_quiz
|
||||
@ -30,6 +32,12 @@ Rails.application.routes.draw do
|
||||
post "/admin/question/:question_id/edit", to: "admin/question#update", as: :admin_update_question
|
||||
patch "/admin/question/:question_id/edit", to: "admin/question#update"
|
||||
|
||||
get "/admin/profile", to: "admin/profile#view", as: :admin_profile
|
||||
post "/admin/profile", to: "admin/profile#update", as: :admin_update_profile
|
||||
get "/admin/profile/edit", to: "admin/profile#edit", as: :admin_edit_profile
|
||||
|
||||
get "/admin", to: "admin#dashboard", as: :admin
|
||||
|
||||
#########################################################################################
|
||||
|
||||
post "/validate", to: "candidate#validate", as: :validate_candidate
|
||||
|
8
db/migrate/20160824183159_add_resets_to_users.rb
Normal file
8
db/migrate/20160824183159_add_resets_to_users.rb
Normal file
@ -0,0 +1,8 @@
|
||||
class AddResetsToUsers < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :users, :reset_token, :string
|
||||
add_column :users, :reset_timestamp, :datetime
|
||||
|
||||
add_index :users, :reset_token
|
||||
end
|
||||
end
|
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160818225721) do
|
||||
ActiveRecord::Schema.define(version: 20160824183159) do
|
||||
|
||||
create_table "answers", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
t.integer "candidate_id"
|
||||
@ -73,6 +73,9 @@ ActiveRecord::Schema.define(version: 20160818225721) do
|
||||
t.boolean "active"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "reset_token"
|
||||
t.datetime "reset_timestamp"
|
||||
t.index ["reset_token"], name: "index_users_on_reset_token", using: :btree
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -36,5 +36,54 @@ module Admin
|
||||
assert_redirected_to admin_login_url
|
||||
assert_match(/incorrect.*email/, flash[:error])
|
||||
end
|
||||
|
||||
test "should get reset_request" do
|
||||
get admin_reset_request_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should process a reset request" do
|
||||
user = users(:admin)
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
post admin_send_reset_url, params: { auth: { email: user.email } }
|
||||
end
|
||||
refute_equal user.reset_token, User.find(user.id).reset_token
|
||||
assert_redirected_to admin_reset_request_url
|
||||
assert_match(/request.*sent/i, flash[:success])
|
||||
end
|
||||
|
||||
test "should redirect with invalid reset_token" do
|
||||
get admin_reset_url('fooBarBaz')
|
||||
assert_redirected_to admin_reset_request_url
|
||||
end
|
||||
|
||||
test "should get reset form" do
|
||||
user = users(:admin)
|
||||
user.setup_reset
|
||||
get admin_reset_url(user.reset_token)
|
||||
assert :success
|
||||
end
|
||||
|
||||
test "should post password reset" do
|
||||
user = users(:admin)
|
||||
user.setup_reset
|
||||
|
||||
post admin_reset_password_url, params: { auth:
|
||||
{ reset_token: user.reset_token, password: '12345', password_confirmation: '12345' } }
|
||||
|
||||
assert_redirected_to admin_auth_path
|
||||
assert_match(/reset.*log/i, flash[:success])
|
||||
end
|
||||
|
||||
test "should fail to reset with mistyped password" do
|
||||
user = users(:admin)
|
||||
user.setup_reset
|
||||
|
||||
post admin_reset_password_url, params: { auth:
|
||||
{ reset_token: user.reset_token, password: '12345', password_confirmation: 'abcde' } }
|
||||
|
||||
assert :success
|
||||
assert flash[:error]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
32
test/controllers/admin/profile_controller_test.rb
Normal file
32
test/controllers/admin/profile_controller_test.rb
Normal file
@ -0,0 +1,32 @@
|
||||
require 'test_helper'
|
||||
|
||||
module Admin
|
||||
class ProfileControllerTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
post admin_auth_url, params: { auth:
|
||||
{ email: 'alan.admin@mailinator.com', password: 'password' } }
|
||||
end
|
||||
|
||||
test "should get view" do
|
||||
get admin_profile_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get admin_edit_profile_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should post update" do
|
||||
post admin_profile_url, params: { user: { name: 'bobby tables' } }
|
||||
assert_redirected_to admin_profile_url
|
||||
assert flash[:success]
|
||||
end
|
||||
|
||||
test "should FAIL update" do
|
||||
post admin_profile_url, params: { user: { name: '' } }
|
||||
assert :success
|
||||
assert flash[:error]
|
||||
end
|
||||
end
|
||||
end
|
@ -28,9 +28,11 @@ module Admin
|
||||
end
|
||||
|
||||
test "should post create" do
|
||||
assert_difference("User.count", 1) do
|
||||
post admin_create_user_url, params: { user:
|
||||
{ email: 'new.user@mailinator.com', name: 'New User', role: 'reviewer' } }
|
||||
assert_difference("ActionMailer::Base.deliveries.size", 1) do
|
||||
assert_difference("User.count", 1) do
|
||||
post admin_create_user_url, params: { user:
|
||||
{ email: 'new.user@mailinator.com', name: 'New User', role: 'reviewer' } }
|
||||
end
|
||||
end
|
||||
assert_redirected_to admin_users_url
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ class RecruiterControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
assert_redirected_to recruiter_path
|
||||
assert flash[:notice]
|
||||
assert flash[:success]
|
||||
end
|
||||
|
||||
test "should fail creation with message" do
|
||||
|
12
test/mailers/previews/user_mailer_preview.rb
Normal file
12
test/mailers/previews/user_mailer_preview.rb
Normal file
@ -0,0 +1,12 @@
|
||||
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer
|
||||
class UserMailerPreview < ActionMailer::Preview
|
||||
def password_reset
|
||||
user = User.find_by(email: 'alan.admin@mailinator.com')
|
||||
UserMailer.password_reset user
|
||||
end
|
||||
|
||||
def welcome
|
||||
user = User.find_by(email: 'alan.admin@mailinator.com')
|
||||
UserMailer.welcome user, '[default-password]'
|
||||
end
|
||||
end
|
20
test/mailers/user_mailer_test.rb
Normal file
20
test/mailers/user_mailer_test.rb
Normal file
@ -0,0 +1,20 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserMailerTest < ActionMailer::TestCase
|
||||
test "password_reset" do
|
||||
user = users(:admin)
|
||||
user.setup_reset
|
||||
mail = UserMailer.password_reset user
|
||||
|
||||
assert_equal [user.email], mail.to
|
||||
assert_match user.reset_token, mail.body.encoded
|
||||
end
|
||||
|
||||
test "welcome" do
|
||||
user = users(:admin)
|
||||
mail = UserMailer.welcome user, 'p0o9i8u7'
|
||||
|
||||
assert_equal [user.email], mail.to
|
||||
assert_match 'p0o9i8u7', mail.body.encoded
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user