Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
venjob
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Huỳnh Thiên Phước
venjob
Commits
02cc1192
Commit
02cc1192
authored
Aug 20, 2020
by
Huỳnh Thiên Phước
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create too expiration_date, modify condition email register
parent
783bd215
Pipeline
#969
failed with stages
in 0 seconds
Changes
12
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
33 additions
and
27 deletions
+33
-27
app/controllers/confirmations_controller.rb
+11
-10
app/controllers/users_controller.rb
+9
-3
app/helpers/sessions_helper.rb
+2
-0
app/mailers/confirmation_mailer.rb
+3
-4
app/models/confirmation.rb
+1
-1
app/models/user.rb
+0
-1
app/views/confirmation_mailer/register_email.html.erb
+2
-2
app/views/confirmations/create.js.erb
+0
-1
app/views/confirmations/new.html.erb
+1
-1
app/views/layouts/_header.html.erb
+1
-1
config/environments/development.rb
+1
-1
config/routes.rb
+2
-2
No files found.
app/controllers/confirmations_controller.rb
View file @
02cc1192
class
ConfirmationsController
<
ApplicationController
def
new
@user
=
Confirmation
.
new
end
def
create
@user
=
Confirmation
.
new
(
email:
params
[
:confirmation
][
:email
].
downcase
)
user_email
=
User
.
find_by
(
email:
params
[
:confirmation
][
:email
].
downcase
)
if
user_email
.
blank?
return
respond_to
{
|
format
|
format
.
js
}
unless
@user
.
save
ConfirmationMailer
.
register_email
(
params
[
:confirmation
][
:email
].
downcase
,
@user
.
confirm_token
).
deliver_later
redirect_to
mail_register_path
else
def
mail_register
email
=
params
[
:confirmation
][
:email
].
downcase
if
User
.
find_by
(
email:
email
)
flash
[
:danger
]
=
'Email existed. Please change !!!'
redirect_to
register_path
redirect_to
register_
step1_
path
end
@user
=
Confirmation
.
find_or_initialize_by
(
email:
email
)
unless
@user
.
save
flash
[
:danger
]
=
"Email formated invalid"
return
redirect_to
register_step1_path
end
ConfirmationMailer
.
register_email
(
@user
).
deliver_later
end
end
app/controllers/users_controller.rb
View file @
02cc1192
class
UsersController
<
ApplicationController
before_action
:sign_in_validation
,
only:
[
:update
,
:my_page
,
:my_info
]
def
my_page
end
...
...
@@ -17,17 +18,22 @@ class UsersController < ApplicationController
end
end
def
mail_register
end
def
registation
@email
=
Confirmation
.
find_by
(
confirm_token:
params
[
:confirm_token
])
return
register_step1_path
unless
@email
expiration_day
=
Time
.
zone
.
now
-
@email
.
updated_at
if
expiration_day
>=
86400
flash
[
:danger
]
=
"Link Confirmation is expiration too 24 hours to confirm. Please update your Email again!"
redirect_to
register_step1_path
else
@user
=
User
.
new
end
end
def
create
@user
=
User
.
new
(
sign_up_params
)
return
respond_to
{
|
format
|
format
.
js
}
unless
@user
.
save
sign_in
@user
redirect_to
my_page_path
end
...
...
app/helpers/sessions_helper.rb
View file @
02cc1192
...
...
@@ -16,6 +16,7 @@ module SessionsHelper
end
def
current_user
return
if
cookies
[
:remember_token
].
blank?
remember_token
=
User
.
digest
(
cookies
[
:remember_token
])
@current_user
||=
User
.
find_by
(
remember_token:
remember_token
)
end
...
...
@@ -25,4 +26,5 @@ module SessionsHelper
cookies
.
delete
(
:remember_token
)
self
.
current_user
=
nil
end
end
app/mailers/confirmation_mailer.rb
View file @
02cc1192
class
ConfirmationMailer
<
ActionMailer
::
Base
def
register_email
(
email
,
confirm_token
)
@email
=
email
@confirm_token
=
confirm_token
mail
(
to:
@email
,
subject:
'Welcome To VeNJOB! Confirm Your Email'
)
def
register_email
(
user
)
@user
=
user
mail
(
to:
user
.
email
,
subject:
'Welcome To VeNJOB! Confirm Your Email'
)
end
end
app/models/confirmation.rb
View file @
02cc1192
class
Confirmation
<
ApplicationRecord
before_save
{
self
.
email
=
email
.
downcase
}
before_
creat
e
:create_confirm_token
before_
sav
e
:create_confirm_token
VALID_EMAIL_REGEX
=
/\A[\w+\-.]+@[a-z\d\-]+(?:\.[a-z\d\-]+)*\.[a-z]+\z/i
validates
:email
,
presence:
true
,
length:
{
maximum:
200
},
format:
{
with:
VALID_EMAIL_REGEX
},
uniqueness:
{
case_sensitive:
false
}
...
...
app/models/user.rb
View file @
02cc1192
...
...
@@ -19,7 +19,6 @@ class User < ApplicationRecord
PASSWORD_FORMAT
=
/\A(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/x
validates
:password
,
format:
{
with:
PASSWORD_FORMAT
,
message:
"is too short or not strength"
}
validates
:password_confirmation
,
presence:
true
def
self
.
new_remember_token
SecureRandom
.
urlsafe_base64
...
...
app/views/confirmation_mailer/register_email.html.erb
View file @
02cc1192
...
...
@@ -3,10 +3,10 @@
<meta
content=
'text/html; charset=UTF-8'
http-equiv=
'Content-Type'
/>
</head>
<body>
<h1>
Welcome
<%=
@email
%>
</h1>
<h1>
Welcome
<%=
@
user
.
email
%>
</h1>
<p>
You're on your way!
</p>
<p>
Let's confirm your email address.
</p>
<p>
By clicking on the following link, you are confirming your email address and agreeing to VeNJOB's Terms of Service.
</p>
<p>
<%=
link_to
'Confirm Email'
,
registation_url
(
confirm_token:
@confirm_token
)
%>
</p>
<p>
<%=
link_to
'Confirm Email'
,
registation_url
(
confirm_token:
@
user
.
confirm_token
)
%>
</p>
</body>
</html>
app/views/confirmations/create.js.erb
deleted
100644 → 0
View file @
783bd215
$(".validation").html("
<%=
escape_javascript
render
(
partial:
'shared/error_messages'
)
%>
");
app/views/confirmations/new.html.erb
View file @
02cc1192
...
...
@@ -4,7 +4,7 @@
<strong>
Register
</strong>
</div>
<div
class=
"form-register"
>
<%=
form_for
(
@user
,
remote:
true
)
do
|
f
|
%>
<%=
form_for
(
:confirmation
,
url:
register_step2_path
)
do
|
f
|
%>
<div
class=
"validation"
></div>
<div
class=
"text-center email-input"
>
...
...
app/views/layouts/_header.html.erb
View file @
02cc1192
...
...
@@ -9,7 +9,7 @@
<li>
<%=
link_to
"Log Out"
,
logout_path
,
class:
"nav-item nav-link"
,
method:
"delete"
%>
</li>
<%
else
%>
<li>
<%=
link_to
"Log In"
,
login_path
,
class:
"nav-item nav-link"
%>
</li>
<li>
<%=
link_to
"Register"
,
register_path
,
class:
"nav-item nav-link"
%>
</li>
<li>
<%=
link_to
"Register"
,
register_
step1_
path
,
class:
"nav-item nav-link"
%>
</li>
<%
end
%>
<li>
<%=
link_to
"Favorite"
,
'#'
,
class:
"nav-item nav-link"
%>
</li>
<li>
<%=
link_to
"History"
,
'#'
,
class:
"nav-item nav-link"
%>
</li>
...
...
config/environments/development.rb
View file @
02cc1192
...
...
@@ -33,7 +33,7 @@ Rails.application.configure do
# config.active_job.queue_adapter = :async
# config.action_mailer.default_options = { from: 'support@venjob.com' }
config
.
action_mailer
.
default_options
=
{
from:
'phuoc2811006@gmail.com'
}
config
.
action_mailer
.
default_options
=
{
from:
ENV
[
'GMAIL_USERNAME'
]
}
config
.
action_mailer
.
default_url_options
=
{
host:
"localhost:3000"
}
config
.
action_mailer
.
raise_delivery_errors
=
true
config
.
action_mailer
.
perform_deliveries
=
true
...
...
config/routes.rb
View file @
02cc1192
...
...
@@ -8,8 +8,8 @@ Rails.application.routes.draw do
get
'/login'
,
to:
'sessions#new'
,
as: :login
delete
'/logout'
,
to:
'sessions#destroy'
,
as: :logout
get
'/register/1'
,
to:
'confirmations#new'
,
as: :register
get
'/register/2'
,
to:
'confirmations#mail_register'
,
as: :mail_register
get
'/register/1'
,
to:
'confirmations#new'
,
as: :register
_step1
post
'/register/2'
,
to:
'confirmations#mail_register'
,
as: :register_step2
get
'/registation/3code=:confirm_token'
,
to:
'users#registation'
,
as: :registation
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment