master
parent
6c6ec56396
commit
002574f559
@ -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,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,0 +1,3 @@
|
||||
// Place all the styles related to the session controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
@ -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/
|
||||
@ -0,0 +1,27 @@
|
||||
class SessionController < ApplicationController
|
||||
|
||||
def create
|
||||
user = User.find_by(email: user_params[:email])
|
||||
|
||||
if user && user.authenticate(user_params[:password])
|
||||
session[:current_user_id] = user.id
|
||||
flash[:message] = "Thanks for logging in, sinner."
|
||||
else
|
||||
flash[:message] = "Email / Password combo does not exist!"
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
session[:current_user_id] = nil
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
return params.require(:user).permit(:email, :password)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,20 @@
|
||||
class UsersController < ApplicationController
|
||||
|
||||
def create
|
||||
@user = User.new(user_params)
|
||||
|
||||
if @user.save
|
||||
flash[:message] = "Good job, you're now an active sinner. Log in, to repent!"
|
||||
else
|
||||
flash[:message] = @user.errors.full_messages.to_sentence
|
||||
end
|
||||
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_params
|
||||
return params.require(:user).permit(:email, :password)
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module SessionHelper
|
||||
end
|
||||
@ -0,0 +1,2 @@
|
||||
module UsersHelper
|
||||
end
|
||||
@ -0,0 +1,10 @@
|
||||
class User < ActiveRecord::Base
|
||||
has_secure_password
|
||||
|
||||
validates :email, presence: true, uniqueness: true
|
||||
validates :password_digest, presence: true
|
||||
|
||||
validates :password, length: {
|
||||
minimum: 8, allow_nil: true
|
||||
}
|
||||
end
|
||||
@ -0,0 +1,29 @@
|
||||
<h1>Welcome, sinner</h1>
|
||||
|
||||
<h3>Please sign <em>up</em> to lift your burdens</h3>
|
||||
|
||||
<form action="<%= users_path %>" method="POST"
|
||||
autocomplete="false">
|
||||
<input type="hidden" name="authenticity_token"
|
||||
value="<%= form_authenticity_token %>">
|
||||
|
||||
<input type="email" name="user[email]"
|
||||
placeholder="your email address"><br/>
|
||||
<input type="password" name="user[password]"
|
||||
placeholder="desired password"><br/>
|
||||
<input type="submit" value="Sign up">
|
||||
</form>
|
||||
|
||||
<h3>Please sign <em>in</em> to lift your burdens</h3>
|
||||
|
||||
<form action="<%= session_path %>" method="POST"
|
||||
autocomplete="false">
|
||||
<input type="hidden" name="authenticity_token"
|
||||
value="<%= form_authenticity_token %>">
|
||||
|
||||
<input type="email" name="user[email]"
|
||||
placeholder="your email address"><br/>
|
||||
<input type="password" name="user[password]"
|
||||
placeholder="desired password"><br/>
|
||||
<input type="submit" value="Sign in">
|
||||
</form>
|
||||
@ -0,0 +1,12 @@
|
||||
class CreateUsers < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :users do |t|
|
||||
t.string :email, null: false
|
||||
t.string :password_digest, null: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
add_index :users, :email
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,28 @@
|
||||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151029150245) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", null: false
|
||||
t.string "password_digest", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "users", ["email"], name: "index_users_on_email", using: :btree
|
||||
|
||||
end
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class SessionControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UsersControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
email: MyString
|
||||
password_digest: MyString
|
||||
|
||||
two:
|
||||
email: MyString
|
||||
password_digest: MyString
|
||||
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class UserTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Reference in new issue