Controller users and user_sessions added
This commit is contained in:
parent
0d10c8ef0a
commit
83259aab54
17 changed files with 179 additions and 0 deletions
3
app/assets/javascripts/user_sessions.coffee
Normal file
3
app/assets/javascripts/user_sessions.coffee
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
3
app/assets/javascripts/users.coffee
Normal file
3
app/assets/javascripts/users.coffee
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||
0
app/assets/stylesheets/application.css
Normal file
0
app/assets/stylesheets/application.css
Normal file
3
app/assets/stylesheets/user_sessions.scss
Normal file
3
app/assets/stylesheets/user_sessions.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the user_sessions controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
3
app/assets/stylesheets/users.scss
Normal file
3
app/assets/stylesheets/users.scss
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the users controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
22
app/controllers/user_sessions_controller.rb
Normal file
22
app/controllers/user_sessions_controller.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class UserSessionsController < ApplicationController
|
||||
|
||||
def new
|
||||
@user_session = UserSession.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user_session = UserSession.new(params[:user_session])
|
||||
if @user_session.save
|
||||
flash[:notice] = "Login successful!"
|
||||
redirect_back_or_default account_url(@current_user)
|
||||
else
|
||||
render :action => :new
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
current_user_session.destroy
|
||||
flash[:notice] = "Logout successful!"
|
||||
redirect_back_or_default new_user_session_url
|
||||
end
|
||||
end
|
||||
43
app/controllers/users_controller.rb
Normal file
43
app/controllers/users_controller.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
class UsersController < ApplicationController
|
||||
|
||||
before_filter :require_user, :only => [:show, :edit, :update]
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(params[:user])
|
||||
|
||||
# Saving without session maintenance to skip
|
||||
# auto-login which can't happen here because
|
||||
# the User has not yet been activated
|
||||
if @user.save
|
||||
flash[:notice] = "Your account has been created."
|
||||
redirect_to signup_url
|
||||
else
|
||||
flash[:notice] = "There was a problem creating you."
|
||||
render :action => :new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
def edit
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
def update
|
||||
@user = current_user # makes our views "cleaner" and more consistent
|
||||
if @user.update_attributes(params[:user])
|
||||
flash[:notice] = "Account updated!"
|
||||
redirect_to account_url
|
||||
else
|
||||
render :action => :edit
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
2
app/helpers/user_sessions_helper.rb
Normal file
2
app/helpers/user_sessions_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module UserSessionsHelper
|
||||
end
|
||||
2
app/helpers/users_helper.rb
Normal file
2
app/helpers/users_helper.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module UsersHelper
|
||||
end
|
||||
7
app/models/user_session.rb
Normal file
7
app/models/user_session.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# User sessions. Refers to the "User" class automatically (by its name).
|
||||
# See also: https://github.com/binarylogic/authlogic
|
||||
class UserSession < Authlogic::Session::Base
|
||||
# specify configuration here, such as:
|
||||
# logout_on_timeout true
|
||||
# ...many more options in the documentation
|
||||
end
|
||||
15
app/views/user_sessions/new.slim
Normal file
15
app/views/user_sessions/new.slim
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
- raise @user_session
|
||||
- form_for @user_session, :as => :user_session, :url => { :action => "create" } do |f|
|
||||
= render "shared/error_messages", :target => @user_session
|
||||
= f.label :email
|
||||
br
|
||||
= f.text_field :email
|
||||
br
|
||||
= f.label :password
|
||||
br
|
||||
= f.password_field :password
|
||||
br
|
||||
= f.check_box :remember_me
|
||||
= f.label :remember_me
|
||||
br
|
||||
= f.submit "Login"
|
||||
20
app/views/users/_form.slim
Normal file
20
app/views/users/_form.slim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
= render "shared/error_messages", :target => @user
|
||||
|
||||
p
|
||||
= form.label :name %
|
||||
br
|
||||
= form.text_field :name
|
||||
p
|
||||
= form.label :email
|
||||
br
|
||||
= form.text_field :email
|
||||
p
|
||||
= form.label :password, form.object.new_record? ? nil : "Change password"
|
||||
br
|
||||
= form.password_field :password
|
||||
p
|
||||
= form.label :password_confirmation
|
||||
br
|
||||
= form.password_field :password_confirmation
|
||||
|
||||
= link_to 'Edit Account', edit_account_path
|
||||
28
app/views/users/show.slim
Normal file
28
app/views/users/show.slim
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
p
|
||||
b Email:
|
||||
=h @user.email
|
||||
|
||||
p
|
||||
b Login count:
|
||||
|
||||
=h @user.login_count
|
||||
|
||||
p
|
||||
b Last request at:
|
||||
=h @user.last_request_at
|
||||
|
||||
p
|
||||
b Last login at:
|
||||
=h @user.last_login_at
|
||||
|
||||
p
|
||||
b Current login at:
|
||||
=h @user.current_login_at
|
||||
|
||||
p
|
||||
b Last login ip:
|
||||
=h @user.last_login_ip
|
||||
|
||||
p
|
||||
b Current login ip:
|
||||
=h @user.current_login_ip
|
||||
7
test/controllers/user_sessions_controller_test.rb
Normal file
7
test/controllers/user_sessions_controller_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class UserSessionsControllerTest < ActionController::TestCase
|
||||
def test_sanity
|
||||
flunk "Need real tests"
|
||||
end
|
||||
end
|
||||
7
test/controllers/users_controller_test.rb
Normal file
7
test/controllers/users_controller_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class UsersControllerTest < ActionController::TestCase
|
||||
def test_sanity
|
||||
flunk "Need real tests"
|
||||
end
|
||||
end
|
||||
7
test/helpers/user_sessions_helper_test.rb
Normal file
7
test/helpers/user_sessions_helper_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class UserSessionsHelperTest < ActionView::TestCase
|
||||
def test_sanity
|
||||
flunk "Need real tests"
|
||||
end
|
||||
end
|
||||
7
test/helpers/users_helper_test.rb
Normal file
7
test/helpers/users_helper_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class UsersHelperTest < ActionView::TestCase
|
||||
def test_sanity
|
||||
flunk "Need real tests"
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue