Validate new organizer
This commit is contained in:
parent
e4df728a04
commit
61b5882d48
1 changed files with 17 additions and 3 deletions
16
vedia.rb
16
vedia.rb
|
|
@ -137,7 +137,7 @@ end
|
|||
|
||||
post '/reset' do
|
||||
@errors = []
|
||||
unless params[:email] =~ URI::MailTo::EMAIL_REGEXP
|
||||
if not params[:email] =~ URI::MailTo::EMAIL_REGEXP
|
||||
@errors << OpenStruct.new(:attribute => :email, :type => :invalid)
|
||||
end
|
||||
if not @errors.empty?
|
||||
|
|
@ -503,8 +503,22 @@ post '/votes/:id/organizers' do
|
|||
require_login
|
||||
find_vote
|
||||
require_organizer
|
||||
@errors = []
|
||||
if not params[:email] =~ URI::MailTo::EMAIL_REGEXP
|
||||
@errors << OpenStruct.new(:attribute => :email, :type => :invalid)
|
||||
else
|
||||
user = User.find_by(email: params[:email])
|
||||
if not user
|
||||
@errors << OpenStruct.new(:attribute => :email, :type => :unknown)
|
||||
@params = params
|
||||
elsif @vote.users.exists?(user.id)
|
||||
@errors << OpenStruct.new(:attribute => :email, :type => :duplicate)
|
||||
else
|
||||
@vote.users << user
|
||||
end
|
||||
end
|
||||
# I'm not displaying the error message yet because it would require choosing
|
||||
# between erb :votes_edit, :votes_show_closed, and :votes_show_open.
|
||||
redirect '/votes/' + @vote.secure_id
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue