Validate email and password
This commit is contained in:
parent
069d565ba9
commit
4faa4fd555
3 changed files with 41 additions and 6 deletions
22
vote.rb
22
vote.rb
|
|
@ -28,6 +28,8 @@ class User < ActiveRecord::Base
|
|||
has_many :ratings
|
||||
has_many :organizers
|
||||
has_many :votes, through: :organizers
|
||||
validates :email, uniqueness: true
|
||||
validates :email, format: URI::MailTo::EMAIL_REGEXP
|
||||
end
|
||||
|
||||
class Organizer < ActiveRecord::Base
|
||||
|
|
@ -81,9 +83,21 @@ get '/signup' do
|
|||
end
|
||||
|
||||
post '/signup' do
|
||||
@user = User.create(email: params[:email],
|
||||
password: hash_password(params[:password]))
|
||||
redirect '/'
|
||||
@user = User.create(email: params[:email])
|
||||
@errors = []
|
||||
if params[:password].empty?
|
||||
@errors << OpenStruct.new(:attribute => :password, :type => :blank)
|
||||
else
|
||||
@user.password = hash_password(params[:password])
|
||||
end
|
||||
if @errors.empty? and @user.valid?
|
||||
@user.save
|
||||
session.clear
|
||||
session[:user_id] = @user.id
|
||||
redirect '/'
|
||||
else
|
||||
erb :signup
|
||||
end
|
||||
end
|
||||
|
||||
get '/login' do
|
||||
|
|
@ -97,7 +111,7 @@ post '/login' do
|
|||
session[:user_id] = user.id
|
||||
redirect '/'
|
||||
else
|
||||
@error = 'Username or password was incorrect'
|
||||
@error = _("Incorrect email or password.")
|
||||
erb :login
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue