Class: ProfileController
Instance Method Summary
collapse
#access_level_control, #charge_session_manager, #check_access_level, #current_user, #edit_checkout
Instance Method Details
#add_avatar ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/profile_controller.rb', line 89
def add_avatar
begin
@current_user.avatar.destroy unless @current_user.avatar.nil?
picture = @current_user.create_avatar({uploaded_file: params.require(:avatar).permit(:uploaded_file)[:uploaded_file]})
@response.set_state 'ok'
@response.add_var ({picture: {id: picture.id, src: picture.uploaded_file.url(:preview)}})
rescue Exception => error
@response.error_state error.message
end
send_response
end
|
#index ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'app/controllers/profile_controller.rb', line 5
def index
if @current_user_card
@type = @current_user_card.whois
@name = @current_user.name
@avatar = @current_user.avatar
if @current_user_card.client?
@sex_all = Client.sex.values.map{ |sex|
{id: sex, name: I18n.t(sex)}
}
@sex = @current_user.sex
@birthday = @current_user.birthday ? @current_user.birthday.strftime("%d.%m.%Y") : nil
@birthday_default_view = @birthday.nil? ? (DateTime.now - 30.years).strftime("%d.%m.%Y") : @birthday
@country = @current_user.country
@city = @current_user.city
end
@access_cards = [
{cards: @current_user_card.nickname_access_cards, classname: 'NicknameAccessCard', by: 'nickname'},
{cards: @current_user_card.email_access_cards, classname: 'EmailAccessCard', by: 'email'},
{cards: @current_user_card.phone_access_cards, classname: 'PhoneAccessCard', by: 'phone'}
]
@access_cards.each do |cards_pack|
count = cards_pack[:classname].constantize.where(user_card_id: @current_user_card.id).count
cards_pack[:add] = count > 0 && count < CONFIG[:access_cards][cards_pack[:by].to_sym][:quantity] ? true : false
end
@ressurection_action = session[:ressurection_action]
session[:ressurection_action]= nil
end
end
|
#kill_avatar ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'app/controllers/profile_controller.rb', line 76
def kill_avatar
begin
@current_user.avatar.destroy if @current_user.avatar.present?
@response.set_state 'ok'
rescue Exception => error
@response.error_state error.message
end
send_response
end
|
#update ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'app/controllers/profile_controller.rb', line 38
def update
if @current_user_card
begin
@current_user.update(get_user_params)
@current_user.errors.messages.each do |message|
@response.add_detail message[0]
end
@response.add_detail 'password' unless @current_user_card.update(password: @user_card_params[:password])
CONFIG[:access_cards].keys.each do |access_card_type|
@user_card_params[access_card_type].each do |access_card|
case access_card['id']
when 0
@response.add_detail access_card_type.to_s unless eval "@current_user_card.#{access_card_type}_access_cards.create(value: access_card['value'])"
else
@response.add_detail access_card_type.to_s unless "@current_user_card.#{access_card_type}_access_cards[access_card['id']].update(value: access_card['value'])"
end
end
end
rescue Exception => error
@response.error_state error.message
end
else
@response.set_state 'shit'
@response.add_detail 'пользователь не найден'
@response.set_url root_path
end
send_response
end
|