Created
January 20, 2013 20:22
-
-
Save d33pfri3d/4581431 to your computer and use it in GitHub Desktop.
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
class SessionsController < ApplicationController | |
def new | |
end | |
def create | |
user = User.find_by_username(params[:username]) | |
if user && user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect_to current_user, notice: "Logged in!" | |
else | |
flash[:error] = "Wrong Username or Password." | |
redirect_to root_url | |
end | |
end | |
def destroy | |
session[:user_id] = nil | |
redirect_to root_url, notice: "Logged out." | |
end | |
end |
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
class UsersController < ApplicationController | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
session[:user_id] = @user.id | |
redirect_to @user, notice: "Thanks for joinging Best Scene" | |
else | |
render 'new' | |
end | |
end | |
def show | |
@user = User.find(params[:id]) | |
end | |
# def self.from_omniauth(auth) | |
# where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| | |
# user.provider = auth.provider | |
# user.uid = auth.uid | |
# user.name = auth.info.name | |
# user.oauth_token = auth.credentials.token | |
# user.oauth_expires_at = Time.at(auth.credentials.expires_at) | |
# user.save! | |
# end | |
# end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment