Kaynağa Gözat

Login, Create Account and Forgot Password views

- Add dependency on haml.
- Add AuthenticationController with login, forgotten_password and
    create_account actions.
- Add actual views for these actions.
- Adapt Bootstrap's login form to a 'void' layout.
Maarten van den Berg 8 yıl önce
ebeveyn
işleme
fd08523f87

+ 3 - 0
Gemfile

@@ -31,6 +31,9 @@ gem 'bcrypt', '~> 3.1.7'
31 31
 gem 'bootstrap-sass', '~> 3.3.6'
32 32
 gem 'autoprefixer-rails'
33 33
 
34
+# Use HAML for templates
35
+gem 'haml'
36
+
34 37
 # Use Capistrano for deployment
35 38
 # gem 'capistrano-rails', group: :development
36 39
 

+ 3 - 0
Gemfile.lock

@@ -61,6 +61,8 @@ GEM
61 61
     ffi (1.9.14)
62 62
     globalid (0.3.7)
63 63
       activesupport (>= 4.1.0)
64
+    haml (4.0.7)
65
+      tilt
64 66
     i18n (0.7.0)
65 67
     jbuilder (2.6.1)
66 68
       activesupport (>= 3.0.0, < 5.1)
@@ -165,6 +167,7 @@ DEPENDENCIES
165 167
   bootstrap-sass (~> 3.3.6)
166 168
   byebug
167 169
   coffee-rails (~> 4.2)
170
+  haml
168 171
   jbuilder (~> 2.5)
169 172
   jquery-rails
170 173
   listen (~> 3.0.5)

+ 3 - 0
app/assets/javascripts/authentication.coffee

@@ -0,0 +1,3 @@
1
+# Place all the behaviors and hooks related to the matching controller here.
2
+# All this logic will automatically be available in application.js.
3
+# You can use CoffeeScript in this file: http://coffeescript.org/

+ 34 - 0
app/assets/stylesheets/application.scss

@@ -10,6 +10,40 @@
10 10
  * files in this directory. Styles in this file should be added after the last require_* statement.
11 11
  * It is generally better to create a new file per style scope.
12 12
  *
13
+ *= require_self
14
+ *= require_tree .
13 15
  */
14 16
 @import "bootstrap-sprockets";
15 17
 @import "bootstrap";
18
+
19
+/* Horizontally distribute ul items.
20
+ *
21
+ * Adapted from the following StackOverflow answer:
22
+ * http://stackoverflow.com/a/13505797 , by user 'joshnh'
23
+ * Licensed under CC-BY-SA 3.0 as per the StackOverflow TOS.
24
+ *
25
+ */
26
+ul.hdis {
27
+    text-align: justify;
28
+    padding-left: 0 !important;
29
+}
30
+
31
+ul.hdis:after {
32
+    content: '';
33
+    display: inline-block;
34
+    width: 100%;
35
+}
36
+
37
+ul.hdis:before {
38
+    content: '';
39
+    display: block;
40
+    margin-top: -1.25em;
41
+}
42
+
43
+ul.hdis li {
44
+    display: inline-block;
45
+    margin-right: -.25em;
46
+    position: relative;
47
+    top: 1.25em;
48
+}
49
+/* End of CC-BY-SA code. */

+ 75 - 0
app/assets/stylesheets/authentication.scss

@@ -0,0 +1,75 @@
1
+// Place all the styles related to the Authentication controller here.
2
+// They will automatically be included in application.css.
3
+// You can use Sass (SCSS) here: http://sass-lang.com/
4
+body .void {
5
+	padding-top: 		40px;
6
+	padding-bottom: 	40px;
7
+	background-color: 	#eee !important;
8
+}
9
+
10
+.central-form {
11
+	max-width: 330px;
12
+	padding: 15px;
13
+	margin: 0 auto;
14
+}
15
+
16
+.central-form .central-form-heading,
17
+.central-form .checkbox {
18
+	margin-bottom: 10px;
19
+}
20
+
21
+.central-form .checkbox {
22
+	font-weight: normal;
23
+}
24
+
25
+.central-form .form-control {
26
+	position: relative;
27
+	height: auto;
28
+	-webkit-box-sizing: border-box;
29
+	 -moz-box-sizing: border-box;
30
+		  box-sizing: border-box;
31
+	padding: 10px;
32
+	font-size: 16px;
33
+}
34
+
35
+.central-form .form-control:focus {
36
+	z-index: 2;
37
+}
38
+
39
+.central-form input.input-top[type="email"] {
40
+	margin-bottom: -1px;
41
+	border-bottom-right-radius: 0;
42
+	border-bottom-left-radius: 0;
43
+}
44
+
45
+.central-form .input-top {
46
+	border-top-left-radius: 4px;
47
+	border-top-right-radius: 4px;
48
+	border-bottom-left-radius: 0;
49
+	border-bottom-right-radius: 0;
50
+}
51
+.central-form .input-middle {
52
+	border-top-left-radius: 0;
53
+	border-top-right-radius: 0;
54
+	border-bottom-left-radius: 4px;
55
+	border-bottom-right-radius: 4px;
56
+}
57
+.central-form .input-bottom {
58
+	border-top-left-radius: 0;
59
+	border-top-right-radius: 0;
60
+	border-bottom-left-radius: 4px;
61
+	border-bottom-right-radius: 4px;
62
+}
63
+
64
+.central-form .input-only {
65
+    border-radius: 4px;
66
+    margin-bottom: 10px !important;
67
+}
68
+
69
+.central-form input[type="password"] {
70
+	margin-bottom: 10px;
71
+	border-top-left-radius: 0;
72
+	border-top-right-radius: 0;
73
+}
74
+@import "bootstrap-sprockets";
75
+@import "bootstrap";

+ 69 - 0
app/assets/stylesheets/void.scss

@@ -0,0 +1,69 @@
1
+body {
2
+	padding-top: 		40px;
3
+	padding-bottom: 	40px;
4
+	background-color: 	#eee;
5
+}
6
+
7
+.central-form {
8
+	max-width: 330px;
9
+	padding: 15px;
10
+	margin: 0 auto;
11
+}
12
+
13
+.central-form .central-form-heading,
14
+.central-form .checkbox {
15
+	margin-bottom: 10px;
16
+}
17
+
18
+.central-form .checkbox {
19
+	font-weight: normal;
20
+}
21
+
22
+.central-form .form-control {
23
+	position: relative;
24
+	height: auto;
25
+	-webkit-box-sizing: border-box;
26
+	 -moz-box-sizing: border-box;
27
+		  box-sizing: border-box;
28
+	padding: 10px;
29
+	font-size: 16px;
30
+}
31
+
32
+.central-form .form-control:focus {
33
+	z-index: 2;
34
+}
35
+.central-form input[type="email"].input-top {
36
+	margin-bottom: -1px;
37
+	border-bottom-right-radius: 0;
38
+	border-bottom-left-radius: 0;
39
+}
40
+
41
+.central-form .input-top {
42
+	border-top-left-radius: 4px;
43
+	border-top-right-radius: 4px;
44
+	border-bottom-left-radius: 0;
45
+	border-bottom-right-radius: 0;
46
+}
47
+.central-form .input-middle {
48
+	border-top-left-radius: 0;
49
+	border-top-right-radius: 0;
50
+	border-bottom-left-radius: 4px;
51
+	border-bottom-right-radius: 4px;
52
+}
53
+.central-form .input-bottom {
54
+	border-top-left-radius: 0;
55
+	border-top-right-radius: 0;
56
+	border-bottom-left-radius: 4px;
57
+	border-bottom-right-radius: 4px;
58
+}
59
+
60
+.central-form .input-only {
61
+    border-radius: 4px;
62
+    padding-bottom: 10px;
63
+}
64
+
65
+.central-form input[type="password"].input-top {
66
+	margin-bottom: 10px;
67
+	border-top-left-radius: 0;
68
+	border-top-right-radius: 0;
69
+}

+ 13 - 0
app/controllers/authentication_controller.rb

@@ -0,0 +1,13 @@
1
+class AuthenticationController < ApplicationController
2
+  def login
3
+    render layout: 'void'
4
+  end
5
+
6
+  def create_password
7
+    render layout: 'void'
8
+  end
9
+
10
+  def forgotten_password
11
+    render layout: 'void'
12
+  end
13
+end

+ 2 - 0
app/helpers/authentication_helper.rb

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

+ 19 - 0
app/views/authentication/create_password.html.haml

@@ -0,0 +1,19 @@
1
+- content_for :title do
2
+  Create password
3
+
4
+.container
5
+  = form_tag '/login', method: 'post', class: 'central-form' do
6
+    %h2.central-form-header.text-center
7
+      Create password
8
+    %p
9
+      Creating an account requires that you have been registered beforehand by an administrator. Contact someone if your email address is not recognized.
10
+
11
+    = email_field_tag :email, '', placeholder: 'Email address', class: 'form-control input-only'
12
+    = submit_tag "Send email", class: 'btn btn-primary btn-lg btn-block'
13
+
14
+  .central-form
15
+    %ul.hdis
16
+      %li
17
+        = link_to "Login",          {action: 'login',           controller: 'authentication'}, {class: 'btn btn-secondary'}
18
+      %li
19
+        = link_to "Forgot password", {action: 'forgotten_password', controller: 'authentication'}, {class: 'btn btn-secondary'}

+ 16 - 0
app/views/authentication/forgotten_password.html.haml

@@ -0,0 +1,16 @@
1
+- content_for :title do
2
+  Forgot password
3
+.container
4
+  = form_tag '/forgot', method: 'post', class:'central-form' do
5
+    %h2.central-form-header.text-center
6
+      Forgot password
7
+
8
+    = email_field_tag :email, '', placeholder: "Email address", class: 'form-control input-only'
9
+    = submit_tag "Send email", class: 'btn btn-primary btn-lg btn-block'
10
+
11
+  .central-form
12
+    %ul.hdis
13
+      %li
14
+        = link_to "Login",          {action: 'login',           controller: 'authentication'}, {class: 'btn btn-secondary'}
15
+      %li
16
+        = link_to "Create account", {action: 'create_password', controller: 'authentication'}, {class: 'btn btn-secondary'}

+ 24 - 0
app/views/authentication/login.html.haml

@@ -0,0 +1,24 @@
1
+- content_for :title do
2
+  Login
3
+
4
+.container
5
+  = form_tag("/login", method: "post", class: "central-form") do
6
+    %h2.central-form-header.text-center
7
+      Please sign in
8
+
9
+    = email_field_tag(:email, '', placeholder: 'Email address', class: 'form-control input-top')
10
+    = password_field_tag(:password, '', placeholder: 'Password', class: 'form-control input-bottom')
11
+
12
+    .checkbox
13
+      %label
14
+        = check_box_tag(:remember_me)
15
+        Remember me
16
+
17
+    = submit_tag("Sign in", class: "btn btn-primary btn-lg btn-block")
18
+
19
+  .central-form
20
+    %ul.hdis
21
+      %li
22
+        = link_to 'Forgot password', {action: 'forgotten_password', controller: 'authentication'}, {class: 'btn btn-secondary'}
23
+      %li
24
+        = link_to 'Create account', {controller: 'authentication', action: 'create_password'}, {class: 'btn btn-secondary'}

+ 14 - 0
app/views/layouts/void.html.erb

@@ -0,0 +1,14 @@
1
+<!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <title><%= yield(:title) %> | Damena</title>
5
+    <%= csrf_meta_tags %>
6
+
7
+    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8
+    <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+  </head>
10
+
11
+  <body class="void">
12
+    <%= yield %>
13
+  </body>
14
+</html>

+ 1 - 1
config/initializers/assets.rb

@@ -8,4 +8,4 @@ Rails.application.config.assets.version = '1.0'
8 8
 
9 9
 # Precompile additional assets.
10 10
 # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11
-# Rails.application.config.assets.precompile += %w( search.js )
11
+#Rails.application.config.assets.precompile += %w( void.css )

+ 6 - 0
config/routes.rb

@@ -1,3 +1,9 @@
1 1
 Rails.application.routes.draw do
2
+  get 'login', to: 'authentication#login'
3
+
4
+  get 'authentication/create_password'
5
+
6
+  get 'authentication/forgotten_password'
7
+
2 8
   # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3 9
 end

+ 19 - 0
test/controllers/authentication_controller_test.rb

@@ -0,0 +1,19 @@
1
+require 'test_helper'
2
+
3
+class AuthenticationControllerTest < ActionDispatch::IntegrationTest
4
+  test "should get login" do
5
+    get authentication_login_url
6
+    assert_response :success
7
+  end
8
+
9
+  test "should get create_password" do
10
+    get authentication_create_password_url
11
+    assert_response :success
12
+  end
13
+
14
+  test "should get forgotten_password" do
15
+    get authentication_forgotten_password_url
16
+    assert_response :success
17
+  end
18
+
19
+end