Add account activation

parent 7d1660db
Pipeline #1295 canceled with stages
in 0 seconds
...@@ -3,13 +3,13 @@ class AccountActivationsController < ApplicationController ...@@ -3,13 +3,13 @@ class AccountActivationsController < ApplicationController
user = User.find_by(email: params[:email]) user = User.find_by(email: params[:email])
if user && !user.activated? && user.authenticated?(:activation, params[:id]) if user && !user.activated? && user.authenticated?(:activation, params[:id])
user.activate user.activate
log_in user helpers.log_in user
flash[:success] = "Account activated!" flash[:success] = "Account activated!"
redirect_to user redirect_to user
else else
flash[:danger] = "Invalid activation link" flash[:danger] = "Invalid activation link"
redirect_to root_url redirect_to root_url
end
end end
end end
end end
...@@ -47,6 +47,13 @@ class User < ApplicationRecord ...@@ -47,6 +47,13 @@ class User < ApplicationRecord
UserMailer.account_activation(self).deliver_now UserMailer.account_activation(self).deliver_now
end end
# Returns true if the given token matches the digest.
def authenticated?(attribute, token)
digest = send("#{attribute}_digest")
return false if digest.nil?
BCrypt::Password.new(digest).is_password?(token)
end
private private
# Converts email to all lower-case. # Converts email to all lower-case.
def downcase_email def downcase_email
...@@ -59,10 +66,4 @@ class User < ApplicationRecord ...@@ -59,10 +66,4 @@ class User < ApplicationRecord
self.activation_digest = User.digest(activation_token) self.activation_digest = User.digest(activation_token)
end end
# Returns true if the given token matches the digest.
def authenticated?(attribute, token)
digest = send("#{attribute}_digest")
return false if digest.nil?
BCrypt::Password.new(digest).is_password?(token)
end
end end
...@@ -11,7 +11,7 @@ Rails.application.configure do ...@@ -11,7 +11,7 @@ Rails.application.configure do
config.action_mailer.raise_delivery_errors = true config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: "fathomless-garden-95089.herokuapp.com" , protocol: "https"}
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com', address: 'smtp.gmail.com',
port: 587, port: 587,
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
"@types/popper.js": "^1.11.0", "@types/popper.js": "^1.11.0",
"bootstrap": "5.0.1", "bootstrap": "5.0.1",
"jquery": "^3.6.0", "jquery": "^3.6.0",
"serve": "^12.0.0",
"turbolinks": "^5.2.0", "turbolinks": "^5.2.0",
"webpack": "^4.46.0", "webpack": "^4.46.0",
"webpack-cli": "^3.3.12" "webpack-cli": "^3.3.12"
...@@ -17,5 +18,13 @@ ...@@ -17,5 +18,13 @@
"version": "0.1.0", "version": "0.1.0",
"devDependencies": { "devDependencies": {
"webpack-dev-server": "^3.11.2" "webpack-dev-server": "^3.11.2"
},
"scripts": {
"dev": "react-scripts start",
"start": "serve -s build",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"heroku-postbuild": "npm run build"
} }
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment