Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented mandatory Steam login.

  • Loading branch information...
commit 80d4813639f2e942169c2753c07445b131e48946 1 parent 995e1a5
@dy-dx dy-dx authored
View
28 app/controllers/omni_controller.rb
@@ -1,28 +0,0 @@
-class OmniController < ApplicationController
-
- skip_before_filter :verify_authenticity_token
-
- def steam_login
- @user = User.find_by_id(session[:user_id])
- if @user
- if @user.steamid.blank?
- @user.steamid = auth_hash.uid
- flash[:notice] = "That steamid has already been taken." unless @user.save
- else
- flash[:notice] = "You cannot change your steamid."
- end
- end
- redirect_to edit_user_path(@user)
- end
-
- def steam_login_failure
- redirect_to current_user
- flash[:notice] = "Could not log you in. #{params[:message]}"
- end
-
- protected
-
- def auth_hash
- request.env['omniauth.auth']
- end
-end
View
32 app/controllers/users_controller.rb
@@ -3,6 +3,7 @@ class UsersController < ApplicationController
before_filter :can_edit, :only => [:edit, :update, :destroy, :confirm_delete]
before_filter :require_admin, :only => [:admin, :ban, :remove_ban]
skip_filter :check_privacy, :only => [:login, :logout]
+ skip_before_filter :verify_authenticity_token, :only => :steam_login
def index
@users = User.paginate(:page => params[:page], :order => 'profile_updated_at desc')
@@ -18,6 +19,7 @@ def new
def create
@user = User.new(params[:user])
+ @user.steamid = session[:steam_id]
render :action => :new and return false unless @user.save
if logged_in?
redirect_to users_path and return true
@@ -77,6 +79,7 @@ def login
if request.post?
@user = User.authenticate(params[:user][:login], params[:user][:password]) unless params[:user].blank?
if @user
+ @user.update_attribute(:steamid, session[:steam_id])
do_login(@user)
else
flash[:notice] = I18n.t(:invalid_user_password_combo)
@@ -93,12 +96,33 @@ def logout
@user.logged_out = true
@user.auth_token = nil
@user.auth_token_exp = nil
- @user.save!
+ @user.save
end
cookies.delete :auth_token
reset_session
flash[:notice] = @flash
- redirect_to login_path
+ redirect_to root_path
+ end
+
+ def steam_login
+ redirect_to root_path and return false if logged_in?
+ if auth_hash.uid.present?
+ @user = User.steam_authenticate(auth_hash.uid)
+ if @user
+ do_login(@user)
+ else
+ session[:steam_id] = auth_hash.uid
+ render :action => :new
+ end
+ else
+ flash[:notice] = I18n.t(:invalid_user_password_combo)
+ redirect_to root_path and return false
+ end
+ end
+
+ def steam_login_failure
+ redirect_to root_path
+ flash[:notice] = "Could not log you in. #{params[:message]}"
end
protected
@@ -115,4 +139,8 @@ def do_login(user)
user.save!
redirect_to root_path
end
+
+ def auth_hash
+ request.env['omniauth.auth']
+ end
end
View
4 app/helpers/application_helper.rb
@@ -49,6 +49,10 @@ def avatar_for(user, style = :medium)
def steam_icon
image_tag("/images/social/steam.png", :class => "steam_icon")
end
+
+ def steam_signin
+ image_tag("/images/social/sits_smallest.png", :class => "steam_signin")
+ end
def steam_for(user)
return "http://steamcommunity.com/profiles/#{user.steamid}"
View
9 app/models/user.rb
@@ -35,12 +35,11 @@ def include?(topic_or_id)
acts_as_voter
has_karma(:posts, :as => :user)
- validates_presence_of :login, :email, :password_hash
+ validates_presence_of :login, :email, :steamid
validates_uniqueness_of :login, :case_sensitive => false
- validates_uniqueness_of :steamid, :allow_blank => true, :allow_nil => true
+ validates_uniqueness_of :steamid
validates_length_of :login, :maximum => 25
validates_format_of :email, :on => :create, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
- validates_confirmation_of :password, :on => :create
validates_confirmation_of :password, :on => :update, :allow_blank => true
before_create :set_defaults
@@ -93,6 +92,10 @@ def self.authenticate(login, password)
find_by_login_and_password_hash(login, encrypt(password))
end
+ def self.steam_authenticate(steamid)
+ find_by_steamid(steamid)
+ end
+
def self.encrypt(password)
Digest::SHA1.hexdigest(password)
end
View
3  app/views/shared/nav.html.erb
@@ -40,8 +40,7 @@
<% end %>
<% if !logged_in? && !locked_out? %>
&nbsp; <%= link_to I18n.t(:search), search_path(:type => current_controller) %> &nbsp;
- <%= link_to I18n.t(:register), register_path %> &nbsp;
- <%= link_to I18n.t(:login), login_path %>
+ <%= link_to steam_signin, "/auth/steam/" %>
<% end %>
</p>
</div>
View
6 app/views/users/edit.html.erb
@@ -13,11 +13,7 @@
</p>
<p class ="label"><label for="user_username">SteamID (You may NOT change this once you add it!)</label></p>
<p>
- <% if @user.steamid.blank? %>
- <a href="/auth/steam/"><img src="http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_small.png"></a>
- <br>
-
- <% else %>
+ <% if @user.steamid.present? %>
<a href="http://steamcommunity.com/profiles/<%= @user.steamid %>" target="_blank">
<img src="http://badges.steamstatus.com/profile/default/steam/<%= @user.steamid %>.png" border="0" alt="Steamprofile badge by Steamprofile.com">
</a>
View
3  app/views/users/login.html.erb
@@ -3,6 +3,9 @@
<%= form_for @user, :url => login_path do |f| %>
<div class="box" id="box-users-login">
<span class="top"><%=t :login %></span>
+ <p class="help">Please enter your username and password.<br /><br />
+ This will link your Steam account to your NATF2 account.
+ </p>
<p class="label"><label for="user_login"><%=t :username %></label></p>
<p><%= f.text_field :login, :style => "width:30%" %></p>
<p class="label"><label for="user_password"><%=t :password %></label></p>
View
9 app/views/users/new.html.erb
@@ -3,15 +3,14 @@
<%= form_for @user do |f| %>
<div class="box" id="box-users-new">
<span class="top"><%=t :register %></span>
+ <p class="help">This is the first time you are logging in with Steam.<br />
+ Please provide additional details to register your account.<br /><br />
+ If you have an existing account, login <%= link_to "here.", login_path %>
+ </p>
<p class="label"><label for="user_username"><%=t :username %></label></p>
<p><%= f.text_field :login, :style => "width:31%" %></p>
<p class="label"><label for="user_email"><%=t :email %></label></p>
<p><%= f.text_field :email, :style => "width:31%" %></p>
- <p class="label"><label for="user_password"><%=t :password_twice %></label></p>
- <p>
- <%= f.password_field :password, :style => "width:15%" %> &nbsp;
- <%= f.password_field :password_confirmation, :style => "width:15%" %>
- </p>
<p>
<%= submit_tag I18n.t(:register), :disable_with => I18n.t(:register) %>&nbsp;
<%= link_to I18n.t(:cancel), root_path %>
View
8 config/routes.rb
@@ -135,9 +135,9 @@
match 'search' => 'search#index'
match 'refresh_chatters' => 'messages#refresh_chatters'
- match 'login' => 'users#login'
match 'logout' => 'users#logout'
- match 'register' => 'users#new'
+ match 'login' => 'users#login'
+ # match 'register' => 'users#new'
match 'admin' => 'settings#index'
match 'blog' => 'articles#index'
@@ -147,6 +147,6 @@
match 'forum' => 'forums#index'
match 'help' => 'home#help'
- match '/auth/:provider/callback', to: 'omni#steam_login'
- match '/auth/failure', to: 'omni#steam_login_failure'
+ match '/auth/:provider/callback', to: 'users#steam_login'
+ match '/auth/failure', to: 'users#steam_login_failure'
end
View
BIN  public/images/social/sits_smallest.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3  public/stylesheets/application.css
@@ -150,6 +150,9 @@ thead .tcm,.avatar-list,.avatar-show,.center{text-align:center;}
.pagination,.fieldWithErrors{display:inline;}
.calendar_date_select td:hover,.calendar_date_select td.selected{background-color:#D1D1D1;}
.steam_icon { margin-bottom: -3px; }
+.steam_signin { margin-bottom: -6px; margin-top: -6px; }
+.help{border:1px solid #999;background:#eee;margin-top:10px;margin-bottom:10px;}
+.help{width:36%;background-color:#FBFBB1;text-align:center;padding:5px 0;}
/*
github.com style (c) Vasily Polovnyov <vast@whiteants.net>
Please sign in to comment.
Something went wrong with that request. Please try again.