Created
June 11, 2018 01:33
-
-
Save Goryudyuma/3c8e80efad3891ef4499174d1c1792ec to your computer and use it in GitHub Desktop.
ISHOCON1をScalaで書いたお気持ち
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
def authenticate(email, password) | |
user = db.xquery('SELECT * FROM users WHERE email = ?', email).first | |
fail Ishocon1::AuthenticationError unless user[:password] == password | |
session[:user_id] = user[:id] | |
end | |
def current_user | |
db.xquery('SELECT * FROM users WHERE id = ?', session[:user_id]).first | |
end | |
def update_last_login(user_id) | |
db.xquery('UPDATE users SET last_login = ? WHERE id = ?', time_now_db, user_id) | |
end | |
post '/login' do | |
authenticate(params['email'], params['password']) | |
update_last_login(current_user[:id]) | |
redirect '/' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment