Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request Team254#9 from morops/user_prefs
Browse files Browse the repository at this point in the history
Added user prefrences
  • Loading branch information
morops committed Dec 27, 2017
2 parents c11748c + a805b9a commit b51c4e2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
25 changes: 14 additions & 11 deletions parts_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ def send_email(to, subject, body)
@user_edit.save
redirect "/users"
end
get "/user/prefrences" do
erb :user_prefs
end

post "/user/prefrences" do
halt(400, "Invalid user.") if @user.nil?
@user.email = params[:email] if params[:email]
@user.first_name = params[:first_name] if params[:first_name]
@user.last_name = params[:last_name] if params[:last_name]
@user.set_password(params[:password]) if params[:password] && !params[:password].empty?
@user.theme = params[:theme] if params[:theme]
@user.save
redirect "/user/prefrences"
end

get "/users/:id/delete" do
require_permission(@user.can_administer?)
Expand All @@ -373,17 +387,6 @@ def send_email(to, subject, body)
redirect "/users"
end

get "/change_password" do
erb :change_password
end

post "/change_password" do
halt(400, "Missing password.") if params[:password].nil? || params[:password].empty?
halt(400, "Invalid old password.") unless User.authenticate(@user.email, params[:old_password])
@user.set_password(params[:password])
@user.save
redirect "/"
end

get "/register" do
@admin_new_user = false
Expand Down
19 changes: 0 additions & 19 deletions views/change_password.erb

This file was deleted.

2 changes: 1 addition & 1 deletion views/header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<li>
<a href="/logout"><i class="icon-off"></i> Logout</a>
<% if @user.wordpress_user_id.nil? %>
<a href="/change_password"><i class="icon-wrench"></i> Change Password</a>
<a href="/user/prefrences"><i class="icon-wrench"></i> User Prefrences</a>
<% end %>
</li>
</ul>
Expand Down
29 changes: 29 additions & 0 deletions views/user_prefs.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%= erb :header %>

<div class="container">
<h2>Edit Prefrences</h2>
<form action="" method="POST">
<label>E-mail</label>
<input type="text" name="email" value="<%= @user.email %>"/>
<label>First Name</label>
<input type="text" name="first_name" value="<%= @user.first_name %>"/>
<label>Last Name</label>
<input type="text" name="last_name" value="<%= @user.last_name %>"/>
<label>Change Password</label>
<input type="password" name="password" />
<label>Verify Password</label>
<input type="password" name="password2" />
<label>Theme</label>
<select name="theme">
<% User::THEMES.each_pair do |key, value| %>
<option value=<%= key %><% if @user.theme == key %> selected<% end %>><%= value %></option>
<% end %>
</select>
<label>
<input type="submit" class="btn btn-primary btn-medium" value="Save"
onclick="return verifyPasswordMatch(this.parentElement.parentElement);" />
</label>
</form>
</div>

<%= erb :footer %>

0 comments on commit b51c4e2

Please sign in to comment.