Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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