volt-user_templates 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b5ea73fe65c14ed0de4064bfc68ee1dca8ed22e
4
+ data.tar.gz: 536c392da63960d6d8c99e4ede4bcb63c04f1ccc
5
+ SHA512:
6
+ metadata.gz: 3a85ff6c08000e56d0dd23b838965cbdfd4b085f5e36030186463f9e64472bac3c636824c15bfcd479c5969e34b4781862b44d83d46ce51724b608326df24768
7
+ data.tar.gz: 1fdbdd5caf3ecb191ba11343e2896d7f3d17874f3d7f1cb663197f041bff55e9aa4dcd3c0c5ff87e66d7a065cfd662d57f3b95e933dffe6bbc7a34c1b992b3e4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in volt-user-templates.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Volt User Templates
2
+
3
+ Volt user templates provide out of the box templates for users to signup, login, and logout. (Forgot password coming soon)
4
+
5
+ ## Install
6
+
7
+ volt-user_templates now ships with volt, but if you have removed it, you can add it back with the following:
8
+
9
+ In your Gemfile, put:
10
+
11
+ ```ruby
12
+ gem 'volt-user_templates'
13
+ ```
14
+
15
+ Then in any component you want to use the templates in, add the following to config/dependencies.rb
16
+
17
+ ```ruby
18
+ component 'user_templates'
19
+ ```
20
+
21
+ ## Use
22
+
23
+ You can use volt-user-template two different ways.
24
+
25
+ 1) You can add routes for it's templates
26
+
27
+ Add the following to your main components route file:
28
+
29
+ ```ruby
30
+ client '/signup', component: 'user_templates', controller: 'signup'
31
+ client '/forgot', component: 'user_templates', controller: 'login', action: 'forgot'
32
+ client '/login', component: 'user_templates', controller: 'login', action: 'index'
33
+ ```
34
+
35
+ Now you can link to /signup and /login
36
+
37
+ 2) You can include the templates as tags:
38
+
39
+ ### Login
40
+
41
+ ```html
42
+ <:user_templates:login post-login-url="/" />
43
+ ```
44
+
45
+ The login template takes an optional post-login-url that will be redirected to after a successful login.
46
+
47
+ ### Signup
48
+
49
+ ```html
50
+ <:user_templates:signup post-signup-url="/" />
51
+ ```
52
+
53
+ Signup takes an optional post-signup-url that will be redirected to after signup.
54
+
55
+ ### Forgot
56
+
57
+ ```html
58
+ <:user_templates:login:forgot post-forgot-url="/login" />
59
+ ```
60
+
61
+ ### Logout
62
+
63
+ volt-user_templates provides a nav bar tag that provides a login/logout link and shows the users name.
64
+
65
+ ```html
66
+ <:user_templates:menu />
67
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,2 @@
1
+ # Component dependencies
2
+ component 'fields'
@@ -0,0 +1 @@
1
+ # Component routes
@@ -0,0 +1,16 @@
1
+ module UserTemplates
2
+ class AccountController < Volt::ModelController
3
+ before_action :require_login
4
+
5
+ def index
6
+ self.model = Volt.fetch_current_user.then(&:buffer)
7
+ end
8
+
9
+ def save
10
+ model.save! do
11
+ flash._notices << 'Account settings saved'
12
+ redirect_to '/'
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module UserTemplates
2
+ class LoginController < Volt::ModelController
3
+ reactive_accessor :errors
4
+ reactive_accessor :login
5
+ reactive_accessor :password
6
+ reactive_accessor :reset_email
7
+
8
+ def do_login
9
+ Volt.login(login, password).then do |res|
10
+ # Successful login, clear out the form
11
+ self.errors = nil
12
+ self.login = ''
13
+ self.password = ''
14
+
15
+ after_login
16
+
17
+ nil
18
+ end.fail do |errors|
19
+ # Login fail
20
+ self.errors = errors
21
+ end
22
+ end
23
+
24
+ def after_login
25
+ redirect_to(attrs.post_login_url || '/')
26
+ end
27
+
28
+ def forgot_url
29
+ url_for(component: 'user_templates', controller: 'login', action: 'forgot')
30
+ end
31
+
32
+ def send_reset_email
33
+ UserTemplateTasks.send_reset_email(reset_email).then do
34
+ self.reset_email = ''
35
+ flash._notices << 'Reset email sent.'
36
+ redirect_to(attrs.post_forgot_url || '/login')
37
+ end.fail do |err|
38
+ flash._errors << err.to_s
39
+ end
40
+ end
41
+
42
+ def use_username?
43
+ Volt.config.public.try(:auth).try(:use_username)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module UserTemplates
2
+ class MenuController < Volt::ModelController
3
+ def show_name
4
+ Volt.fetch_current_user.then do |user|
5
+ user._name || user._email || user._username
6
+ end
7
+ end
8
+
9
+ def is_active?
10
+ url.path.split('/')[1] == 'login'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ module UserTemplates
2
+ class SignupController < Volt::ModelController
3
+ def index
4
+ self.model = store._users.buffer
5
+ end
6
+
7
+ def signup
8
+ # Get login and password to login
9
+ login = model.send(:"_#{User.login_field}")
10
+ password = model._password
11
+
12
+ save!.then do |result|
13
+ flash._notices << "Signup successful"
14
+
15
+ # On a successful signup, then login
16
+ Volt.login(login, password).then do
17
+ after_signup
18
+ end.fail do |errors|
19
+ # Show the error (probably only the server goes down)
20
+ flash._errors << errors.to_s
21
+ end
22
+ end.fail do |err|
23
+ puts "ERR: #{err.inspect}"
24
+ end
25
+ end
26
+
27
+ def after_signup
28
+ post_signup_url = attrs.post_signup_url || '/'
29
+
30
+ # Redirect to post signup url
31
+ redirect_to post_signup_url
32
+ end
33
+
34
+ def use_username?
35
+ Volt.config.public.try(:auth).try(:use_username)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ require 'digest'
2
+
3
+ class UserTemplateTasks < Volt::Task
4
+ def password_reset_token(user_id)
5
+ Digest::SHA256.hexdigest("#{user_id}||#{Volt.config.app_secret}")
6
+ end
7
+
8
+ def send_reset_email(email)
9
+ # Find user by e-mail
10
+ Volt.skip_permissions do
11
+ store._users.where(email: email).fetch_first do |user|
12
+ if user
13
+ reset_token = password_reset_token(user.id)
14
+
15
+ reset_url = "http://#{Volt.config.domain}/#{reset_token}"
16
+
17
+ Mailer.deliver('user_templates/mailers/forgot',
18
+ {to: email, name: user._name, reset_url: reset_url}
19
+ )
20
+ else
21
+ raise "There is no account with the e-mail of #{email}."
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ <:Title>
2
+ Your Account
3
+
4
+ <:Body>
5
+ <div class="row">
6
+ <div class="col-md-6 col-md-offset-3">
7
+ <div class="span4 offset4 well">
8
+ <legend>Basic Info</legend>
9
+
10
+ <form e-submit="save">
11
+ <:fields:text value="{{ _name }}" />
12
+ <:fields:textarea value="{{ _bio }}" />
13
+ <button class="btn btn-info btn-block">Save</button>
14
+ </form>
15
+
16
+ </div>
17
+ <hr />
18
+ <div class="span4 offset4 well">
19
+ <legend>Update Password</legend>
20
+ <form e-submit="save">
21
+ <:fields:text type="password" value="{{ _password }}" />
22
+ <button class="btn btn-info btn-block">Save</button>
23
+ </form>
24
+ </div>
25
+ </div>
26
+ </div>
@@ -0,0 +1,21 @@
1
+ <:Title>
2
+ Forgot your Password
3
+
4
+ <:Body>
5
+ <div class="row">
6
+ <div class="col-md-6 col-md-offset-3">
7
+ <div class="span4 offset4 well">
8
+ <legend>Forgot your Password</legend>
9
+
10
+ <p>We'll e-mail you a reset link.</p>
11
+ <form e-submit="send_reset_email">
12
+ <div class="form-group">
13
+ <label class="control-label">Email</label>
14
+ <input class="form-control" type="text" value="{{ reset_email }}" autofocus />
15
+ </div>
16
+
17
+ <button class="btn btn-info btn-block">Reset Password</button>
18
+ </form>
19
+ </div>
20
+ </div>
21
+ </div>
@@ -0,0 +1,39 @@
1
+ <:Title>
2
+ Login
3
+
4
+ <:Body>
5
+ <div class="row">
6
+ <div class="col-md-6 col-md-offset-3">
7
+ <div class="span4 offset4 well">
8
+ <legend>Please Login</legend>
9
+
10
+ <form e-submit="do_login">
11
+ {{ if errors.present? }}
12
+ <div class="alert alert-danger">{{ errors }}</div>
13
+ {{ end }}
14
+
15
+ <div class="form-group">
16
+ <label class="control-label">
17
+ {{ if use_username? }}
18
+ Username
19
+ {{ else }}
20
+ Email
21
+ {{ end }}
22
+ </label>
23
+ <input class="form-control" type="text" value="{{ login }}" autofocus />
24
+ </div>
25
+
26
+ <div class="form-group">
27
+ <label class="control-label">Password <small style="font-weight: normal;">(<a tabindex="-1" href="{{ forgot_url }}">forgot password</a>)</small></label>
28
+ <input class="form-control" type="password" value="{{ password }}">
29
+ </div>
30
+
31
+ <button class="btn btn-info btn-block">Login</button>
32
+ </form>
33
+
34
+ <hr />
35
+ Don't have an account? <a href="/signup">Signup here</a>
36
+ </div>
37
+ </div>
38
+ </div>
39
+
@@ -0,0 +1,41 @@
1
+ <:Subject>
2
+ Reset your Password
3
+
4
+ <:Html>
5
+ <html>
6
+ <body>
7
+ <table cellspacing="0" cellpadding="0" border="0" style="color: #333; background: #fff; padding: 0; margin: 0; width: 100%; font: 15px/1.25em 'Helvetica Neue', Arial, Helvetica;">
8
+ <tbody>
9
+ <tr width="100%">
10
+ <td valign="top" align="left" style="background: #f0f0f0; font: 15px/1.25em 'Helvetica Neue', Arial, Helvetica;">
11
+ <table style="border: none; padding: 0 18px; margin: 50px auto; width: 500px;">
12
+ <tbody>
13
+ <tr width="100%" height="57">
14
+ <td valign="top" align="left" style="border-top-left-radius: 4px; border-top-right-radius: 4px; background: #337ab7; padding: 12px 18px; text-align: center; font-weight: bold; font-size: 28px; color: #fff; vertical-align: middle;">
15
+ {{ Volt.config.app_name }}
16
+ </td>
17
+ </tr>
18
+ <tr width="100%">
19
+ <td valign="top" align="left" style="border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; background:#fff; padding: 18px;">
20
+ <h1 style="font-size: 20px; margin: 0; color: #333;"> Hello {{ name }}, </h1>
21
+ <p style="font: 15px/1.25em 'Helvetica Neue', Arial, Helvetica; color: #333;"> We heard you needed to reset your password. Click the button below and you'll be redirected to a page where you can reset your password.</p>
22
+ <p style="font: 15px/1.25em 'Helvetica Neue', Arial, Helvetica; margin-bottom: 0; text-align: center; color: #333;">
23
+ <a href="{{ reset_url }}" style="border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; background: #5cb85c; color: #fff; cursor: pointer; display: block; font-weight: 700; font-size: 16px; line-height: 1.25em; margin: 24px auto 24px; padding: 10px 18px; text-decoration: none; width: 180px; text-align: center;"> Reset Password </a>
24
+ </p>
25
+ </td>
26
+ </tr>
27
+ </tbody>
28
+ </table>
29
+ </td>
30
+ </tr>
31
+ </tbody>
32
+ </table>
33
+ </body>
34
+ </html>
35
+
36
+ <:Text>
37
+ Hey {{ name }},
38
+
39
+ We heard you needed to reset your password. Go to the following url to reset your password:
40
+
41
+ {{ reset_url }}
@@ -0,0 +1,25 @@
1
+ <:Body>
2
+
3
+ {{ if Volt.current_user }}
4
+ <li class="dropdown">
5
+ <a href="#" class="dropdown-toggle" data-toggle="dropdown">
6
+ <span class="glyphicon glyphicon-user"></span>
7
+ {{ show_name }}
8
+ <span class="caret"></span>
9
+ </a>
10
+ <ul class="dropdown-menu" role="menu">
11
+ <li>
12
+ <a href="/account">Account</a>
13
+ </li>
14
+ <li class="divider"></li>
15
+ <li><a e-click="Volt.logout">Logout</a></li>
16
+ </ul>
17
+ </li>
18
+ {{ else }}
19
+ <li class="{{ if is_active? }}active{{ end }}">
20
+ <a href="/login">
21
+ <span class="glyphicon glyphicon-user"></span>
22
+ Login
23
+ </a>
24
+ </li>
25
+ {{ end }}
@@ -0,0 +1,27 @@
1
+ <:Title>
2
+ Signup
3
+
4
+ <:Body>
5
+ <div class="row">
6
+ <div class="col-md-6 col-md-offset-3">
7
+ <div class="span4 offset4 well">
8
+ <legend>Signup</legend>
9
+
10
+ <form e-submit="signup">
11
+ {{ if use_username? }}
12
+ <:fields:text value="{{ _username }}" />
13
+ {{ else }}
14
+ <:fields:text value="{{ _email }}" />
15
+ {{ end}}
16
+ <:fields:text type="password" value="{{ _password }}" />
17
+ <hr />
18
+ <:fields:text value="{{ _name }}" label="Full Name" />
19
+
20
+ <button class="btn btn-info btn-block">Signup</button>
21
+ <hr />
22
+ Already have an account? <a href="/login">Login here</a>
23
+
24
+ </form>
25
+ </div>
26
+ </div>
27
+ </div>
@@ -0,0 +1,4 @@
1
+ module Volt
2
+ class UserTemplates
3
+ end
4
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ version = File.read(File.expand_path('../VERSION', __FILE__)).strip
6
+
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "volt-user_templates"
10
+ spec.version = version
11
+ spec.authors = ["Ryan Stout"]
12
+ spec.email = ["ryan@agileproductions.com"]
13
+ spec.summary = %q{Volt user templates provide out of the box templates for users to signup, login, and logout. }
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "volt-fields", "~> 0.1.0"
23
+ spec.add_dependency "volt-mailer", "~> 0.1.0"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: volt-user_templates
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Stout
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: volt-fields
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: volt-mailer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - ryan@agileproductions.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - VERSION
67
+ - app/user_templates/config/dependencies.rb
68
+ - app/user_templates/config/routes.rb
69
+ - app/user_templates/controllers/account_controller.rb
70
+ - app/user_templates/controllers/login_controller.rb
71
+ - app/user_templates/controllers/menu_controller.rb
72
+ - app/user_templates/controllers/signup_controller.rb
73
+ - app/user_templates/tasks/user_template_tasks.rb
74
+ - app/user_templates/views/account/index.html
75
+ - app/user_templates/views/login/forgot.html
76
+ - app/user_templates/views/login/index.html
77
+ - app/user_templates/views/mailers/forgot.email
78
+ - app/user_templates/views/menu/index.html
79
+ - app/user_templates/views/signup/index.html
80
+ - lib/volt/user-templates.rb
81
+ - volt-user_templates.gemspec
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ metadata: {}
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 2.4.5
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Volt user templates provide out of the box templates for users to signup,
106
+ login, and logout.
107
+ test_files: []