Last active
March 14, 2020 18:07
-
-
Save donrestarone/db9e10d23a222b1fc747b6232c4a0e84 to your computer and use it in GitHub Desktop.
a simple user model that generates a unique token for a newly signed up user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
has_secure_password | |
validates_format_of :email, :with => /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/ | |
def generate_email_confirmation_link | |
path = ENV["CLIENT_APPLICATION_ROOT"] | |
token = CoreModules::JsonWebToken.encode({user_id: self.id}, 30.minutes.from_now) | |
return "#{path}/users/confirmations/#{token}?type=#{'email'}" | |
end | |
def verify_email | |
if !self.email_verified? | |
self.update(email_verified: true) | |
else | |
return false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment