Skip to content

Instantly share code, notes, and snippets.

@Goryudyuma
Created June 11, 2018 01:33
Show Gist options
  • Save Goryudyuma/3c8e80efad3891ef4499174d1c1792ec to your computer and use it in GitHub Desktop.
Save Goryudyuma/3c8e80efad3891ef4499174d1c1792ec to your computer and use it in GitHub Desktop.
ISHOCON1をScalaで書いたお気持ち
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