constructor-core 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -186,6 +186,7 @@ h3 {
186
186
  list-style: none;
187
187
  margin-top: 15px;
188
188
  margin-left: 60px;
189
+ margin-bottom: 25px;
189
190
 
190
191
  &:first-child {
191
192
  margin-left: 0;
@@ -3,5 +3,27 @@
3
3
  module ConstructorCore
4
4
  class ApplicationController < ApplicationController
5
5
  helper_method :current_user
6
+
7
+ private
8
+
9
+ def authenticate_user!
10
+ warden.authenticate!
11
+ end
12
+
13
+ def user_signed_in?
14
+ !!current_user
15
+ end
16
+
17
+ def current_user
18
+ @current_user ||= warden.authenticate
19
+ end
20
+
21
+ def user_session
22
+ current_user && warden.session
23
+ end
24
+
25
+ def warden
26
+ request.env['warden']
27
+ end
6
28
  end
7
29
  end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module ConstructorCore
4
+ class UsersController < ApplicationController
5
+ layout 'constructor_core/application_admin'
6
+
7
+ def profile
8
+ @user = current_user
9
+ end
10
+
11
+ def update_password
12
+ @user = current_user
13
+
14
+ if params[:user][:password] == params[:user][:password_confirm]
15
+ @user.password = params[:user][:password]
16
+
17
+ if @user.save
18
+ redirect_to '/login', :notice => t(:password_changed)
19
+ return
20
+ end
21
+ end
22
+
23
+ redirect_to :back, :notice => t(:password_error_confirm)
24
+ end
25
+ end
26
+ end
@@ -1,25 +1,5 @@
1
1
  module ConstructorCore
2
2
  module ApplicationHelper
3
- def authenticate_user!
4
- warden.authenticate!
5
- end
6
-
7
- def user_signed_in?
8
- !!current_user
9
- end
10
-
11
- def current_user
12
- @current_user ||= warden.authenticate
13
- end
14
-
15
- def user_session
16
- current_user && warden.session
17
- end
18
-
19
- def warden
20
- request.env['warden']
21
- end
22
-
23
3
  def gravatar_icon(user_email = '', size = 40)
24
4
  gravatar_url = 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
25
5
  user_email.strip!
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ConstructorCore
4
4
  class User < ActiveRecord::Base
5
- devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :timeoutable #:confirmable, :registerable, :omniauthable, :lockable, :encryptable
5
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable, :timeoutable, :registerable #:confirmable, :omniauthable, :lockable, :encryptable
6
6
  attr_accessible :email, :password, :password_confirmation, :remember_me
7
7
  end
8
8
  end
@@ -11,6 +11,7 @@
11
11
  = f.label :password, :class => 'control-label'
12
12
  .controls
13
13
  = f.password_field :password
14
+
14
15
  - if devise_mapping.rememberable?
15
16
  .control-group
16
17
  .controls
@@ -0,0 +1,16 @@
1
+ - content_for :page_title do
2
+ =t :profile
3
+
4
+ = form_for @current_user, method: :post do |f|
5
+ .form-horizontal
6
+ .control-group
7
+ = f.label :password, :class => 'control-label'
8
+ .controls
9
+ = f.password_field :password, required: true
10
+ .control-group
11
+ = f.label :password_confirmation, :class => 'control-label'
12
+ .controls
13
+ = f.password_field :password_confirm, required: true
14
+ .control-group
15
+ .controls
16
+ = f.submit t(:save_password), :class => "btn btn-primary"
@@ -39,20 +39,15 @@
39
39
  = link_to '/admin/templates' do
40
40
  %i.icon-film
41
41
  =t :templates
42
- /
43
- %li
44
- = link_to '/admin/users' do
45
- %i.icon-group
46
- =t :users
47
42
 
48
- - if user_signed_in?
43
+ - if current_user
49
44
  %ul.nav.pull-right
50
45
  %li
51
- = link_to @current_user do
46
+ = link_to core.user_path(current_user.id) do
52
47
  = image_tag gravatar_icon(current_user.email, 48), width: 24, height: 24, class: 'avatar'
53
48
  %span= current_user.email
54
49
  %li
55
- = link_to @current_user, class: 'logout', method: :delete do
50
+ = link_to core.destroy_user_session_path, method: :delete do
56
51
  %i.icon-signout
57
52
  =t :logout
58
53
 
@@ -7,4 +7,8 @@ en:
7
7
  no: 'No'
8
8
  error: 'Error'
9
9
  sitemap: 'Site map'
10
- remember_me: 'Remember me'
10
+ remember_me: 'Remember me'
11
+ profile: 'Profile'
12
+ password_error_confirm: 'Password confirmation failed'
13
+ save_password: 'Save password'
14
+ password_changed: 'Password changed'
@@ -8,6 +8,10 @@ ru:
8
8
  error: 'Ошибка'
9
9
  sitemap: 'Карта сайта'
10
10
  remember_me: 'Запомнить меня'
11
+ profile: 'Профиль'
12
+ save_password: 'Сохранить пароль'
13
+ password_changed: 'Пароль успешно изменен'
14
+ password_error_confirm: 'Пароли не совпадают'
11
15
 
12
16
  activerecord:
13
17
  attributes:
data/config/routes.rb CHANGED
@@ -1,14 +1,18 @@
1
1
  ConstructorCore::Engine.routes.draw do
2
- devise_for :users, {
3
- class_name: 'ConstructorCore::User',
4
- skip: [:sessions, :passwords],
5
- module: :devise
6
- }
2
+ scope 'admin' do
3
+ get 'profile/:id' => 'users#profile', as: :user
4
+ post 'profile/:id' => 'users#update_password'
5
+
6
+ devise_for :users, {
7
+ class_name: 'ConstructorCore::User',
8
+ module: :devise
9
+ }
10
+ end
7
11
 
8
12
  as :user do
9
13
  get '/admin' => 'sessions#new'
10
14
  get '/login' => 'sessions#new'
11
15
  post '/login' => 'sessions#create'
12
- get '/logout' => 'sessions#destroy'
16
+ delete '/logout' => 'sessions#destroy'
13
17
  end
14
18
  end
@@ -1,56 +1,24 @@
1
1
  class DeviseUsers < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table ConstructorCore::User.table_name do |t|
4
- ## Database authenticatable
5
4
  t.string :email, :null => false, :default => ""
6
5
  t.string :encrypted_password, :null => false, :default => ""
7
-
8
- ## Recoverable
9
6
  t.string :reset_password_token
10
7
  t.datetime :reset_password_sent_at
11
-
12
- ## Rememberable
13
8
  t.datetime :remember_created_at
14
-
15
- ## Trackable
16
9
  t.integer :sign_in_count, :default => 0
17
10
  t.datetime :current_sign_in_at
18
11
  t.datetime :last_sign_in_at
19
12
  t.string :current_sign_in_ip
20
13
  t.string :last_sign_in_ip
21
-
22
- ## Encryptable
23
- # t.string :password_salt
24
-
25
- ## Confirmable
26
- # t.string :confirmation_token
27
- # t.datetime :confirmed_at
28
- # t.datetime :confirmation_sent_at
29
- # t.string :unconfirmed_email # Only if using reconfirmable
30
-
31
- ## Lockable
32
- # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
33
- # t.string :unlock_token # Only if unlock strategy is :email or :both
34
- # t.datetime :locked_at
35
-
36
- ## Token authenticatable
37
14
  t.string :authentication_token
38
-
39
-
40
- # Uncomment below if timestamps were not included in your original model.
41
- # t.timestamps
42
15
  end
43
16
 
44
17
  add_index ConstructorCore::User.table_name, :email, :unique => true
45
18
  add_index ConstructorCore::User.table_name, :reset_password_token, :unique => true
46
- # add_index :users, :confirmation_token, :unique => true
47
- # add_index :users, :unlock_token, :unique => true
48
- # add_index :users, :authentication_token, :unique => true
49
19
  end
50
20
 
51
21
  def self.down
52
- # By default, we don't want to make any assumption about how to roll back a migration when your
53
- # model already existed. Please edit below which fields you would like to remove in this migration.
54
22
  drop_table ConstructorCore::User.table_name
55
23
  end
56
24
  end
@@ -1,3 +1,3 @@
1
1
  module ConstructorCore
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -110,6 +110,7 @@ files:
110
110
  - app/assets/stylesheets/constructor_core/main.css.scss
111
111
  - app/controllers/constructor_core/application_controller.rb
112
112
  - app/controllers/constructor_core/sessions_controller.rb
113
+ - app/controllers/constructor_core/users_controller.rb
113
114
  - app/helpers/constructor_core/application_helper.rb
114
115
  - app/models/constructor_core/user.rb
115
116
  - app/views/constructor_core/devise/confirmations/new.html.haml
@@ -123,6 +124,7 @@ files:
123
124
  - app/views/constructor_core/devise/shared/_links.html.haml
124
125
  - app/views/constructor_core/devise/unlocks/new.html.haml
125
126
  - app/views/constructor_core/sessions/new.html.haml
127
+ - app/views/constructor_core/users/profile.haml
126
128
  - app/views/layouts/constructor_core/application_admin.haml
127
129
  - config/environments/production.rb
128
130
  - config/initializers/devise.rb