forked from hotsh/rstat.us
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_handling.rb
32 lines (29 loc) · 977 Bytes
/
user_handling.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Rstatus
# EMPTY USERNAME HANDLING - quick and dirty
before do
@error_bar = ""
if current_user && (current_user.username.nil? or current_user.username.empty? or !current_user.username.match(/profile.php/).nil?)
@error_bar = haml :_username_error, :layout => false
end
end
get '/reset-username' do
unless current_user.nil? || current_user.username.empty?
redirect "/"
end
haml :reset_username
end
post '/reset-username' do
exists = User.first :username => params[:username]
if !params[:username].nil? && !params[:username].empty? && exists.nil?
if current_user.reset_username(params)
flash[:notice] = "Thank you for updating your username"
else
flash[:notice] = "Your username could not be updated"
end
redirect "/"
else
flash[:notice] = "Sorry, that username has already been taken or is not valid. Please try again."
haml :reset_username
end
end
end