Controller users and user_sessions added

This commit is contained in:
Christoph Haas 2016-02-26 17:34:36 +01:00
parent 0d10c8ef0a
commit 83259aab54
17 changed files with 179 additions and 0 deletions

View 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/

View 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/

View file

View 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/

View 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/

View 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

View 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

View file

@ -0,0 +1,2 @@
module UserSessionsHelper
end

View file

@ -0,0 +1,2 @@
module UsersHelper
end

View 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

View 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"

View 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
View 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

View file

@ -0,0 +1,7 @@
require "test_helper"
class UserSessionsControllerTest < ActionController::TestCase
def test_sanity
flunk "Need real tests"
end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class UsersControllerTest < ActionController::TestCase
def test_sanity
flunk "Need real tests"
end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class UserSessionsHelperTest < ActionView::TestCase
def test_sanity
flunk "Need real tests"
end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class UsersHelperTest < ActionView::TestCase
def test_sanity
flunk "Need real tests"
end
end