Class: MerbWords::Passwords

Inherits:
Application
  • Object
show all
Defined in:
app/controllers/passwords.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
# File 'app/controllers/passwords.rb', line 12

def create
  display(@password = Password.new, :layout => false)
end

#create_postObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/passwords.rb', line 16

def create_post
  password = Password.new(params[:password])
  if password.save
    session[:mui_password_id] = password.id
    session[:mui_message] = url(:merb_ui_message, :title => 'Password created', :tone => 'positive')
    mui_window_redirect
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Unable to create password', :body => mui_list(password.errors), :tone => 'negative')
    session[:mui_window] = slice_url(:password_create)
    mui_window_redirect
  end
end

#deleteObject



64
65
66
# File 'app/controllers/passwords.rb', line 64

def delete
  render :layout => false
end

#delete_deleteObject



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

def delete_delete
  password = Password.get!(session[:mui_password_id])
  if password.destroy
    session.delete(:mui_password_id)
    session[:mui_message] = url(:merb_ui_message, :title => 'Password deleted', :tone => 'positive')
    mui_window_redirect
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Unable to delete password', :body => mui_list(password.errors), :tone => 'negative')
    session[:mui_window] = slice_url(:password_delete)
    mui_window_redirect
  end
end

#exitObject



6
7
8
9
10
# File 'app/controllers/passwords.rb', line 6

def exit
  session.delete(:mui_password_id)
  session[:mui_message] = url(:merb_ui_message, :title => 'Exited', :tone => 'positive')
  mui_window_redirect
end

#readObject



29
30
31
32
33
34
35
# File 'app/controllers/passwords.rb', line 29

def read
  if Password.first
    display(@password = Password.new, :layout => false)
  else
    redirect slice_url(:password_create)
  end
end

#read_postObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/passwords.rb', line 37

def read_post
  encrypted = encrypt(params[:password])
  if password_match = Password.first(:encrypted => encrypted)
    session[:mui_password_id] = password_match.id
    session[:mui_message] = url(:merb_ui_message, :title => 'Password correct', :tone => 'positive')
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Password incorrect', :tone => 'negative')
    session[:mui_window] = slice_url(:password_read)
  end
  mui_window_redirect
end

#updateObject



49
50
51
# File 'app/controllers/passwords.rb', line 49

def update
  display(@password = Password.new, :layout => false)
end

#update_postObject



53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/passwords.rb', line 53

def update_post
  password = Password.get!(session[:mui_password_id])
  if password.update_attributes(params[:password])
    session[:mui_message] = url(:merb_ui_message, :title => 'Password updated', :tone => 'positive')
  else
    session[:mui_message] = url(:merb_ui_message, :title => 'Unable to update password', :body => mui_list(password.errors), :tone => 'negative')
    session[:mui_window] = slice_url(:password_update)
  end
  mui_window_redirect
end