Add account activation

parent 7d1660db
Pipeline #1295 canceled with stages
in 0 seconds
......@@ -3,7 +3,7 @@ class AccountActivationsController < ApplicationController
user = User.find_by(email: params[:email])
if user && !user.activated? && user.authenticated?(:activation, params[:id])
user.activate
log_in user
helpers.log_in user
flash[:success] = "Account activated!"
redirect_to user
else
......@@ -11,5 +11,5 @@ class AccountActivationsController < ApplicationController
redirect_to root_url
end
end
end
end
......@@ -47,6 +47,13 @@ class User < ApplicationRecord
UserMailer.account_activation(self).deliver_now
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
# Converts email to all lower-case.
def downcase_email
......@@ -59,10 +66,4 @@ class User < ApplicationRecord
self.activation_digest = User.digest(activation_token)
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
......@@ -11,7 +11,7 @@ Rails.application.configure do
config.action_mailer.raise_delivery_errors = true
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 = {
address: 'smtp.gmail.com',
port: 587,
......
......@@ -10,6 +10,7 @@
"@types/popper.js": "^1.11.0",
"bootstrap": "5.0.1",
"jquery": "^3.6.0",
"serve": "^12.0.0",
"turbolinks": "^5.2.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
......@@ -17,5 +18,13 @@
"version": "0.1.0",
"devDependencies": {
"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