Skip to content

Instantly share code, notes, and snippets.

@donrestarone
Last active March 14, 2020 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donrestarone/db9e10d23a222b1fc747b6232c4a0e84 to your computer and use it in GitHub Desktop.
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.
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