Class: UsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/users_controller.rb', line 16

def create
   
   if(params.has_key?(:account) && params.has_key?(:balance) && params.has_key?(:name) && params.has_key?(:pin))
     @user=User.new(user_params)
     if @user.save
        redirect_to root_url
      else
        render "new"
      end
   elsif params.has_key?(:account)
    @user=User.find(:first, :conditions=>["account = ?", params[:account]])
    if @user.nil?
       redirect_to 
       elsif @user.==params[:account].to_i
         redirect_to pin_check_path
       else
         redirect_to 
       end
   elsif params.has_key?(:pin)
     @user=User.find(:first, :conditions=>["pin = ?", params[:pin]])
     if @user.nil?
       redirect_to 
       elsif @user.pin==params[:pin].to_i
         session[:user_id] = @user.id
         redirect_to home_path
        else
          redirect_to pin_check_path
       end
     end 
end

#deposite_moneyObject


92
93
94
95
96
97
98
# File 'app/controllers/users_controller.rb', line 92

def deposite_money
  @user=User.find(session[:user_id])
  @user.balance=@user.balance + params[:balance].to_f
    @user.update_attribute(:balance, @user.balance)
  
  redirect_to deposite_succ_path
end

#deposite_succObject


89
90
91
# File 'app/controllers/users_controller.rb', line 89

def deposite_succ
  @user=User.find(session[:user_id])
end

#destroyObject


99
100
101
102
103
# File 'app/controllers/users_controller.rb', line 99

def destroy
  session[:user_id] = nil
  puts session[:user_id]
  redirect_to root_url
end

#editObject


47
48
49
# File 'app/controllers/users_controller.rb', line 47

def edit
  @user=User.new
end

#homeObject


60
61
62
# File 'app/controllers/users_controller.rb', line 60

def home
  @user = User.find(session[:user_id])
end

#indexObject


3
4
5
6
7
# File 'app/controllers/users_controller.rb', line 3

def index
#   logger.info "Index User info"
#   Rails.logger.info "sample text"
# @user=User.find(:first, :conditions=>["account = ?", params[:account]])
end

#newObject


10
11
12
13
# File 'app/controllers/users_controller.rb', line 10

def new 
  logger.info "Index the userdetails"
  @user=User.new
end

#showObject


51
52
53
54
# File 'app/controllers/users_controller.rb', line 51

def show
   @user = User.find(session[:user_id])
 puts session[:user_id]
end

#user_paramsObject


105
106
107
108
# File 'app/controllers/users_controller.rb', line 105

def user_params
  allow = [:name, :account, :pin, :balance]
  params.permit(allow)
end

#withdraw_moneyObject


67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/users_controller.rb', line 67

def withdraw_money
  @user=User.find(session[:user_id])
 
  if params[:balance].to_f > @user.balance
  
    redirect_to withdrw_err_path
   else
     
    @user.balance=@user.balance - params[:balance].to_f
    @user.update_attribute(:balance, @user.balance)
  
  redirect_to withdrw_succ_path
  end
end

#withdrw_errObject


82
83
84
# File 'app/controllers/users_controller.rb', line 82

def withdrw_err
   @user=User.find(session[:user_id])
end

#withdrw_succObject


86
87
88
# File 'app/controllers/users_controller.rb', line 86

def withdrw_succ
  @user=User.find(session[:user_id])
end