Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve sign up #41

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions app/controllers/unconfirmed_user_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
class UnconfirmedUserController < ApplicationController

def list
@unconfirmed_users = LoginInfo.all
end

def show
@unconfirmed_user = UnconfirmedUser.find(params[:id])
end

def new
@unconfirmed_user = UnconfirmedUser.new
end
Expand Down
23 changes: 4 additions & 19 deletions app/views/login_info/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<div class="col-md-12">

<!--Sign up-->
<div class="col-md-4">
<div class="col-md-12">
<h1>Sign Up</h1>
<div class="row-fluid">
<%= form_for :login_info, :action => 'create', :url => login_info_create_path do |form| %>
Expand All @@ -102,6 +102,9 @@
<%= form.password_field :password, :class => 'input-signtype', :id => 'sign_up_password', :placeholder => 'Password', :required => '' %>
</div>
<br>
<div class="span5">
<p style="color:white;">(Must contain: 8 characters, 1 uppercase, 1 lowercase, 1 special character, and 1 digit)</p>
</div>
<div class="span5">
<%= form.password_field :password_confirmation, :class => 'input-signtype', :id => 'sign_up_confirm', :placeholder => 'Repeat Password', :required => '' %>
</div>
Expand All @@ -117,24 +120,6 @@
<%= link_to "Existing user? Sign In Here!", login_info_login_path, :class => 'forgot' %>
</div>
</div> <!-- end of Sign up-->

<!-- Password Rules -->
<div class="col-md-4">
<h1>Password Rules</h1>
<div class="row-fluid">
<div class="span12">
<ul class="password-rules" style="color:white">
<li>Password must contain at least:</li>
<ul style="color:white;text-align:left">
<li>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;●&emsp;8 characters</li>
<li>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;●&emsp;1 uppercase letter</li>
<li>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;●&emsp;1 special character</li>
<li>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;●&emsp;1 digit</li>
</ul>
</ul>
</div>
</div><!-- /row-fluid -->
</div> <!-- end of Password Rules-->
</div>
</div> <!-- bg head content -->
</div>
Expand Down
72 changes: 72 additions & 0 deletions spec/controllers/unconfirmed_user_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require "rails_helper"

RSpec.describe UnconfirmedUserController, type: :controller do
let(:unconfirmed_user) { create(:unconfirmed_user) }
let(:login_info) { create(:login_info) }

describe "GET #new" do
it "assigns a new unconfirmed user to @unconfirmed_user" do
@unconfirmed_user = UnconfirmedUser.new
get :new, params: { id: @unconfirmed_user.to_param, template: 'unconfirmed_user/new' }
expect(response).to render_template :new
end
end

describe "POST #verify" do
let!(:unconfirmed_user) do
UnconfirmedUser.create!(
unconfirmed_email: '[email protected]',
encrypted_password: 'Test#123',
confirmation_token: '123456',
confirmation_sent_at: Time.current
)
end

context "with valid token" do
it "verifies the user and redirects to new_general_info_path" do
post :verify, params: { unconfirmed_user: { confirmation_token: unconfirmed_user.confirmation_token } }
expect(flash[:success]).to eq("You Have Successfully Verified your email!")
expect(response).to redirect_to(new_general_info_path)
end
end

context "with invalid token" do
it "redirects to unconfirmed_user_new_path with error" do
post :verify, params: { unconfirmed_user: { confirmation_token: "654321" } }
expect(flash[:error]).to eq("Invalid token")
expect(response).to redirect_to(unconfirmed_user_new_path)
end
end
end

describe "POST #regenerate_token" do
context "when session is nil" do
it "redirects to unconfirmed_user_new_path with error" do
post :regenerate_token
expect(flash[:error]).to eq("No session found. Please try signing-up again to resend the verification token!")
expect(response).to redirect_to(unconfirmed_user_new_path)
end
end

context "when user is not found" do
it "redirects to unconfirmed_user_new_path with error" do
session[:current_login_user] = { 'email' => '[email protected]' }
post :regenerate_token
expect(flash[:error]).to eq("Invalid email. Please try signing-up again to resend the verification token!")
expect(response).to redirect_to(unconfirmed_user_new_path)
end
end

context "when user is found" do
it "regenerates the token and sends email" do
@unconfirmed_user = UnconfirmedUser.new
session[:current_login_user] = { 'email' => '[email protected]' }
@unconfirmed_user = UnconfirmedUser.create!( unconfirmed_email: '[email protected]', encrypted_password: 'Test#123', confirmation_token: '654321', confirmation_sent_at: Time.current)
post :regenerate_token
expect(flash[:notice]).to eq('We have sent you a new code to verify the email!')
expect(response).to redirect_to(unconfirmed_user_new_path)
@unconfirmed_user.destroy
end
end
end
end
Loading