assigned a user id, does not "appear" to have screwed anything up
This commit is contained in:
@@ -31,7 +31,7 @@ class AdminController < ApplicationController
|
|||||||
|
|
||||||
def delete_user
|
def delete_user
|
||||||
user = User.find_by_id(params[:admin_id])
|
user = User.find_by_id(params[:admin_id])
|
||||||
if user && !(current_user.id == user.id)
|
if user && !(current_user.user_id == user.user_id)
|
||||||
user.delete
|
user.delete
|
||||||
message = true
|
message = true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class ApplicationController < ActionController::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def current_user
|
def current_user
|
||||||
@current_user ||= User.find_by_id(session[:id].to_s)
|
@current_user ||= User.find_by_user_id(session[:user_id].to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticated
|
def authenticated
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class SessionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
if user
|
if user
|
||||||
session[:id] = user.id if User.where(:id => user.id).exists?
|
session[:user_id] = user.user_id if User.where(:user_id => user.user_id).exists?
|
||||||
redirect_to home_dashboard_index_path
|
redirect_to home_dashboard_index_path
|
||||||
else
|
else
|
||||||
# Removed this code, just doesn't seem specific enough!
|
# Removed this code, just doesn't seem specific enough!
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class UsersController < ApplicationController
|
|||||||
def create
|
def create
|
||||||
user = User.new(params[:user])
|
user = User.new(params[:user])
|
||||||
if user.save
|
if user.save
|
||||||
session[:id] = user.id
|
session[:user_id] = user.user_id
|
||||||
redirect_to home_dashboard_index_path
|
redirect_to home_dashboard_index_path
|
||||||
else
|
else
|
||||||
@user = user
|
@user = user
|
||||||
@@ -22,11 +22,12 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
current_user.skip_user_id_assign = true
|
||||||
current_user.update_attributes(params[:user].reject { |k| k == ("password" || "password_confirmation") })
|
current_user.update_attributes(params[:user].reject { |k| k == ("password" || "password_confirmation") })
|
||||||
pass = params[:user][:password]
|
pass = params[:user][:password]
|
||||||
current_user.password = pass if !(pass.blank?)
|
current_user.password = pass if !(pass.blank?)
|
||||||
current_user.save!
|
current_user.save!
|
||||||
redirect_to user_account_settings_path(:user_id => current_user.id)
|
redirect_to user_account_settings_path(:user_id => current_user.user_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ class User < ActiveRecord::Base
|
|||||||
validates_presence_of :email
|
validates_presence_of :email
|
||||||
validates_uniqueness_of :email
|
validates_uniqueness_of :email
|
||||||
validates_format_of :email, :with => /.+@.+\..+/i
|
validates_format_of :email, :with => /.+@.+\..+/i
|
||||||
|
attr_accessor :skip_user_id_assign
|
||||||
|
before_save :assign_user_id, :on => :create
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def self.authenticate(email, password)
|
def self.authenticate(email, password)
|
||||||
@@ -25,5 +28,13 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
return auth
|
return auth
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assign_user_id
|
||||||
|
unless @skip_user_id_assign.present?
|
||||||
|
user = User.order("user_id").last
|
||||||
|
uid = user.user_id.to_i + 1 if user && user.user_id && !(User.exists?(:user_id => "#{user.user_id.to_i + 1}"))
|
||||||
|
self.user_id = uid.to_s if uid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ function makeActive(){
|
|||||||
};
|
};
|
||||||
|
|
||||||
function loadTable(){
|
function loadTable(){
|
||||||
$("#userDataTable").load("/admin/"+ <%=current_user.id %> + "/get_all_users")
|
$("#userDataTable").load("/admin/"+ <%=current_user.user_id %> + "/get_all_users")
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(
|
$(document).ready(
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ $('#submit_button').click(function() {
|
|||||||
$("#editAcct").modal('hide');
|
$("#editAcct").modal('hide');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/admin/" + <%= @user.id %> + "/update_user.json",
|
url: "/admin/" + <%= @user.user_id %> + "/update_user.json",
|
||||||
data: valuesToSubmit,
|
data: valuesToSubmit,
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
@@ -83,7 +83,7 @@ $('#delete_button').click(function() {
|
|||||||
$("#editAcct").modal('hide');
|
$("#editAcct").modal('hide');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/admin/" + <%= @user.id %> + "/delete_user.json",
|
url: "/admin/" + <%= @user.user_id %> + "/delete_user.json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
$('#success').show(500).delay(1500).fadeOut();
|
$('#success').show(500).delay(1500).fadeOut();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
<ul class="dropdown-menu pull-right">
|
<ul class="dropdown-menu pull-right">
|
||||||
<li>
|
<li>
|
||||||
<%= link_to "account settings", user_account_settings_path(:user_id => current_user.id) %>
|
<%= link_to "account settings", user_account_settings_path(:user_id => current_user.user_id) %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to "logout", logout_path %>
|
<%= link_to "logout", logout_path %>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
</li>
|
</li>
|
||||||
<% if is_admin? %>
|
<% if is_admin? %>
|
||||||
<li id='admin'>
|
<li id='admin'>
|
||||||
<%= link_to admin_dashboard_path(:admin_id => current_user.id) do %>
|
<%= link_to admin_dashboard_path(:admin_id => current_user.user_id) do %>
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<span class="fs1" aria-hidden="true" data-icon=""></span>
|
<span class="fs1" aria-hidden="true" data-icon=""></span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
if user
|
if user
|
||||||
session[:id] = user.id if User.where(:id => user.id).exists?
|
session[:user_id] = user.user_id if User.where(:user_id => user.user_id).exists?
|
||||||
redirect_to home_dashboard_index_path
|
redirect_to home_dashboard_index_path
|
||||||
else
|
else
|
||||||
flash[:error] = e.message
|
flash[:error] = e.message
|
||||||
@@ -103,7 +103,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
if user
|
if user
|
||||||
session[:id] = user.id if User.where(:id => user.id).exists?
|
session[:user_id] = user.user_id if User.where(:user_id => user.user_id).exists?
|
||||||
redirect_to home_dashboard_index_path
|
redirect_to home_dashboard_index_path
|
||||||
else
|
else
|
||||||
flash[:error] = "Either your username and password is incorrect" #e.message
|
flash[:error] = "Either your username and password is incorrect" #e.message
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class CreateUsers < ActiveRecord::Migration
|
|||||||
t.boolean :admin
|
t.boolean :admin
|
||||||
t.string :first_name
|
t.string :first_name
|
||||||
t.string :last_name
|
t.string :last_name
|
||||||
|
t.string :user_id
|
||||||
|
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(:version => 20130424220355) do
|
|||||||
t.boolean "admin"
|
t.boolean "admin"
|
||||||
t.string "first_name"
|
t.string "first_name"
|
||||||
t.string "last_name"
|
t.string "last_name"
|
||||||
|
t.string "user_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|||||||
+5
-5
@@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
|
|
||||||
users = [
|
users = [
|
||||||
{:email => "admin@metacorp.com", :admin => true, :password => "admin1234", :first_name => "Admin", :last_name => ""},
|
{:email => "admin@metacorp.com", :admin => true, :password => "admin1234", :first_name => "Admin", :last_name => "", :user_id =>1 },
|
||||||
{:email => "jack@metacorp.com", :admin => false, :password => "yankeessuck", :first_name => "Jack", :last_name => "Mannino"},
|
{:email => "jack@metacorp.com", :admin => false, :password => "yankeessuck", :first_name => "Jack", :last_name => "Mannino", :user_id => 2},
|
||||||
{:email => "jim@metacorp.com", :admin => false, :password => "alohaowasp", :first_name => "Jim", :last_name => "Manico"},
|
{:email => "jim@metacorp.com", :admin => false, :password => "alohaowasp", :first_name => "Jim", :last_name => "Manico", :user_id =>3 },
|
||||||
{:email => "mike@metacorp.com", :admin => false, :password => "motorcross1445", :first_name => "Mike", :last_name => "McCabe"},
|
{:email => "mike@metacorp.com", :admin => false, :password => "motorcross1445", :first_name => "Mike", :last_name => "McCabe", :user_id =>4 },
|
||||||
{:email => "ken@metacorp.com", :admin => false, :password => "citrusblend", :first_name => "Ken", :last_name => "Johnson"}
|
{:email => "ken@metacorp.com", :admin => false, :password => "citrusblend", :first_name => "Ken", :last_name => "Johnson", :user_id =>5 }
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user