@@ -8,6 +8,7 @@ class AdminController < ApplicationController | |||||
AdminSetting.set(key, value) | AdminSetting.set(key, value) | ||||
end | end | ||||
end | end | ||||
flash.now[:notice] = 'Admin settings updated.' | |||||
render 'index' | render 'index' | ||||
end | end | ||||
end | end |
@@ -9,8 +9,20 @@ class UsersController < ApplicationController | |||||
def login | def login | ||||
if request.post? | if request.post? | ||||
# do user login logic | |||||
redirect_to root_url | |||||
if params[:username].nil? || params[:username].empty? || | |||||
params[:password].nil? || params[:password].empty? | |||||
flash.now[:alert] = 'Both a character name and password are required.' | |||||
render 'login' and return | |||||
end | |||||
user = User.find_by(name: params[:username]) | |||||
if user.nil? || !user.authenticate(params[:password]) | |||||
flash.now[:alert] = 'Incorrect character name or password.' | |||||
render 'login' and return | |||||
end | |||||
flash.now[:alert] = 'Login successful.' | |||||
render 'login' and return | |||||
# redirect_to root_url | |||||
end | end | ||||
end | end | ||||
@@ -20,4 +32,10 @@ class UsersController < ApplicationController | |||||
redirect_to root_url | redirect_to root_url | ||||
end | end | ||||
end | end | ||||
def reset | |||||
if request.post? | |||||
# do user reset logic | |||||
end | |||||
end | |||||
end | end |
@@ -6,10 +6,13 @@ | |||||
</span> | </span> | ||||
<% end %> | <% end %> | ||||
<span id="user-links"> | <span id="user-links"> | ||||
<%= link_to "Signup", controller: "users", action: "signup" %> | |||||
<%= link_to 'Signup', controller: 'users', action: 'signup' %> | |||||
• | • | ||||
<%= link_to "Login", controller: "users", action: "login" %> | |||||
<%= link_to 'Login', controller: 'users', action: 'login' %> | |||||
• | • | ||||
<%= link_to "Admin", controller: "admin", action: "index" %> | |||||
<%= link_to 'Admin', controller: 'admin', action: 'index' %> | |||||
</span> | </span> | ||||
</header> | </header> | ||||
<% flash.each do |name, msg| %> | |||||
<div class="flash">FLASH: <%= name %>: <%= msg %></div> | |||||
<% end %> |
@@ -5,7 +5,17 @@ | |||||
<%= form_tag do %> | <%= form_tag do %> | ||||
<table> | <table> | ||||
<tr> | <tr> | ||||
<td><%= label_tag('username', 'Character name') %></td> | |||||
<td><%= text_field_tag('username') %></td> | |||||
</tr> | |||||
<tr> | |||||
<td><%= label_tag('password', 'Password') %></td> | |||||
<td><%= password_field_tag('password') %></td> | |||||
</tr> | |||||
<tr> | |||||
<td colspan="2"><%= submit_tag('Login') %></td> | <td colspan="2"><%= submit_tag('Login') %></td> | ||||
</tr> | </tr> | ||||
</table> | </table> | ||||
<% end %> | <% end %> | ||||
<p><%= link_to "Forgot your password?", controller: 'users', action: 'reset' %></p> |
@@ -0,0 +1,15 @@ | |||||
<% provide(:title, 'Reset Password') %> | |||||
<h1>Reset Password</h1> | |||||
<%= form_tag do %> | |||||
<table> | |||||
<tr> | |||||
<td><%= label_tag('email', 'Email address') %></td> | |||||
<td><%= email_field_tag('email') %></td> | |||||
</tr> | |||||
<tr> | |||||
<td colspan="2"><%= submit_tag('Send password reset email') %></td> | |||||
</tr> | |||||
</table> | |||||
<% end %> |
@@ -7,6 +7,8 @@ Rails.application.routes.draw do | |||||
post '/login' => 'users#login' | post '/login' => 'users#login' | ||||
get '/logout' => 'users#logout' | get '/logout' => 'users#logout' | ||||
post '/logout' => 'users#logout' | post '/logout' => 'users#logout' | ||||
get '/reset' => 'users#reset' | |||||
post '/reset' => 'users#reset' | |||||
get '/admin' => 'admin#index' | get '/admin' => 'admin#index' | ||||
post '/admin' => 'admin#update' | post '/admin' => 'admin#update' | ||||