Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899class SessionsController < ApplicationController def new redirect_to(redirect_path) if current_user.present? end
def create @user = User.find_by(email: session_params[:email]) if @user.nil? redirect_back( alert: "No account exists with that email address.", fallback_location: new_session_path, ) return end
if @user.password_digest.nil? if @user.twitch redirect_back( alert: <<~ALERT, Your account exists, but you created it with a Twitch link and have not set a password. Please sign in with Twitch then set a password from the settings page to enable email/password login. (If you do not have access to your Twitch account, use the "I forgot my password" feature.) ALERT fallback_location: new_session_path, ) return end
if @user.google redirect_back( alert: <<~ALERT, Your account exists, but you created it with a Google link and have not set a password. Please sign in with Google then set a password from the settings page to enable email/password login.' (If you do not have access to your Google account, use the "I forgot my password" feature.) ALERT fallback_location: new_session_path, ) return end
redirect_back( alert: <<~ALERT, Your account exists but has no password set, so cannot be logged into. Please use the "I forgot my password" feature to set a password. ALERT fallback_location: new_session_path, ) return end
if @user.authenticate(session_params[:password]) sign_in(@user) redirect_to( redirect_path, notice: "'Hoy!! Signed in as #{@user.name}.", ) return end
redirect_back( alert: "Invalid email or password.", fallback_location: new_session_path, ) end
def in head :ok end
def destroy auth_session.invalidate! redirect_back fallback_location: root_path, notice: "Signed out. (>-.-)>" end
def failure redirect_to redirect_path, alert: "Error: #{params[:message]}" end
private
def sign_in(user) create_auth_session(user) auth_session.persist! end
def redirect_path request.env["omniauth.origin"] || cookies.delete("return_to") || root_path end
def session_params params.require(:session).permit(:email, :password) endend