snapuser 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/users_controller.rb +4 -4
- data/app/controllers/sessions_controller.rb +6 -6
- data/app/controllers/users_controller.rb +2 -6
- data/app/helpers/sessions_helper.rb +11 -18
- data/app/views/admin/users/edit.html.erb +1 -1
- data/app/views/admin/users/index.html.erb +2 -4
- data/app/views/admin/users/new.html.erb +1 -1
- data/app/views/sessions/new.html.erb +0 -2
- data/app/views/users/edit.html.erb +1 -1
- data/config/locales/fr.yml +40 -0
- data/config/routes.rb +0 -2
- data/lib/snapuser.rb +4 -2
- data/lib/snapuser/version.rb +1 -1
- data/lib/tasks/snapuser_tasks.rake +0 -4
- metadata +3 -3
- data/app/views/users/profile.html.erb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b68c03b024e5cb5dfa5eb265b3a91956bba8f31
|
4
|
+
data.tar.gz: 42d487e79165055c859670013c03aa2b7ecd7e4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84c708628437a8e2b5cc27999964e7c0163062f84987ddb3c97950b6dd168f013757ef462d79d61d0b17db0e765ab91786ca655b79679c04a3d4a01318b15de1
|
7
|
+
data.tar.gz: 3d6ad9a363bea08144061f512649fcd4553cf00ab6b94df11ddfc3039beb29b0ed1fda70d8f46f56fbaa6bd4a7ba9355787d0517a6b28f58e716819c86013f12
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class Admin::UsersController < ApplicationController
|
2
|
-
before_action { |c| c.authorize_level(
|
2
|
+
before_action { |c| c.authorize_level(Snapuser.superuser_level) }
|
3
3
|
layout 'admin'
|
4
4
|
|
5
5
|
def index
|
@@ -14,7 +14,7 @@ class Admin::UsersController < ApplicationController
|
|
14
14
|
def create
|
15
15
|
@user = User.new(user_params)
|
16
16
|
if @user.save
|
17
|
-
redirect_to admin_users_path, success: t('
|
17
|
+
redirect_to admin_users_path, success: t('snapuser.admin.new.success')
|
18
18
|
else
|
19
19
|
render 'new'
|
20
20
|
end
|
@@ -27,7 +27,7 @@ class Admin::UsersController < ApplicationController
|
|
27
27
|
def update
|
28
28
|
@user = User.find(params[:id])
|
29
29
|
if @user.update_attributes(user_params)
|
30
|
-
redirect_to admin_users_path, success: t('
|
30
|
+
redirect_to admin_users_path, success: t('snapuser.admin.edit.success')
|
31
31
|
else
|
32
32
|
render 'edit'
|
33
33
|
end
|
@@ -35,7 +35,7 @@ class Admin::UsersController < ApplicationController
|
|
35
35
|
|
36
36
|
def destroy
|
37
37
|
User.find(params[:id]).destroy
|
38
|
-
redirect_to admin_activities_path, success: t('
|
38
|
+
redirect_to admin_activities_path, success: t('snapuser.admin.destroy.success')
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class SessionsController < ApplicationController
|
2
|
-
before_action :
|
2
|
+
before_action :redirect_if_connected, except: :destroy
|
3
3
|
|
4
4
|
def new
|
5
5
|
end
|
@@ -7,22 +7,22 @@ class SessionsController < ApplicationController
|
|
7
7
|
def create
|
8
8
|
@user = User.where("lower(name) = ?", params[:session][:name].strip.downcase).first
|
9
9
|
if @user && @user.authenticate(params[:session][:password])
|
10
|
-
params[:session][:remember_me] ==
|
11
|
-
redirect_back_or profile_path, success: t('session.
|
10
|
+
sign_in(@user, permanent: params[:session][:remember_me] == "1")
|
11
|
+
redirect_back_or profile_path, success: t('snapuser.session.success')
|
12
12
|
else
|
13
|
-
flash.now[:error] = t('session.
|
13
|
+
flash.now[:error] = t('snapuser.session.error')
|
14
14
|
render 'new'
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def destroy
|
19
19
|
sign_out
|
20
|
-
redirect_to root_path, success: t('session.destroy.success')
|
20
|
+
redirect_to root_path, success: t('snapuser.session.destroy.success')
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def
|
25
|
+
def redirect_if_connected
|
26
26
|
redirect_to profile_path unless current_user.nil?
|
27
27
|
end
|
28
28
|
|
@@ -1,11 +1,7 @@
|
|
1
1
|
class UsersController < ApplicationController
|
2
|
-
before_action
|
3
|
-
before_action only: [:profile] { |c| c.authorize_level(4) }
|
2
|
+
before_action { |c| c.authorize_level(Snapuser.can_edit) }
|
4
3
|
layout 'admin'
|
5
4
|
|
6
|
-
def profile
|
7
|
-
end
|
8
|
-
|
9
5
|
def edit
|
10
6
|
@user = current_user
|
11
7
|
end
|
@@ -14,7 +10,7 @@ class UsersController < ApplicationController
|
|
14
10
|
@user = current_user
|
15
11
|
if @user.update_attributes(user_params)
|
16
12
|
sign_in @user
|
17
|
-
redirect_to profile_path, success: t('
|
13
|
+
redirect_to profile_path, success: t('snapuser.edit.success')
|
18
14
|
else
|
19
15
|
render 'new'
|
20
16
|
end
|
@@ -6,21 +6,10 @@ module SessionsHelper
|
|
6
6
|
# - a user to sign in
|
7
7
|
# * *Returns* :
|
8
8
|
#
|
9
|
-
def sign_in(user)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# Sign in a user with a cookie (remove after 2 months)
|
15
|
-
#
|
16
|
-
# * *Args* :
|
17
|
-
# - a user to sign in
|
18
|
-
# * *Returns* :
|
19
|
-
#
|
20
|
-
def sign_in_permanent(user)
|
21
|
-
cookies[:remember_token] = { value: user.remember_token, expires: Time.now + 2592000 }
|
22
|
-
self.current_user = user
|
23
|
-
end
|
9
|
+
def sign_in(user, permanent: false)
|
10
|
+
cookies[:remember_token] = { value: user.remember_token, expires: (Time.now + 2592000 if permanent) }
|
11
|
+
self.current_user = user
|
12
|
+
end
|
24
13
|
|
25
14
|
def current_user=(user)
|
26
15
|
@current_user = user
|
@@ -70,15 +59,19 @@ module SessionsHelper
|
|
70
59
|
session.delete(:return_to)
|
71
60
|
end
|
72
61
|
|
73
|
-
def authorize_level?(level
|
62
|
+
def authorize_level?(level)
|
74
63
|
current_user && current_user.level <= level
|
75
64
|
end
|
76
65
|
|
77
|
-
def authorize_level(level
|
66
|
+
def authorize_level(level)
|
78
67
|
unless authorize_level?(level)
|
79
68
|
store_location
|
80
|
-
redirect_to login_path, error: "
|
69
|
+
redirect_to login_path, error: t("snapuser.errors.unauthorized")
|
81
70
|
end
|
82
71
|
end
|
83
72
|
|
73
|
+
def require_login
|
74
|
+
redirect_to login_path, error: t("snapuser.errors.unconnected") unless signed_in?
|
75
|
+
end
|
76
|
+
|
84
77
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
fr:
|
2
|
+
snapuser:
|
3
|
+
admin:
|
4
|
+
index:
|
5
|
+
title: "Les utilisateurs"
|
6
|
+
edit:
|
7
|
+
title: "Editer un utilisateur"
|
8
|
+
success: "Utilisateur enregistré"
|
9
|
+
new:
|
10
|
+
title: "Ajouter un utilisateur"
|
11
|
+
success: "Utilisateur crée"
|
12
|
+
edit:
|
13
|
+
title: "Editer mon compte"
|
14
|
+
success: "Compte mis à jour"
|
15
|
+
destroy:
|
16
|
+
success: "Utilisateur supprimé"
|
17
|
+
errors:
|
18
|
+
unauthorized: "Non autorisé"
|
19
|
+
unconnected: "Veuillez vous connecter"
|
20
|
+
session:
|
21
|
+
success: "Connecté !"
|
22
|
+
error: "Mot de passe ou/et nom d'utilisateur invalide !"
|
23
|
+
destroy:
|
24
|
+
success: "Déconnecté !"
|
25
|
+
activerecord:
|
26
|
+
attributes:
|
27
|
+
user:
|
28
|
+
name: "Nom d'utilisateur"
|
29
|
+
password: "Mot de passe"
|
30
|
+
password_confirmation: "Confirmation du mot de passe"
|
31
|
+
helpers:
|
32
|
+
submit:
|
33
|
+
user:
|
34
|
+
create: "S'inscrire"
|
35
|
+
update: "Mettre à jour"
|
36
|
+
label:
|
37
|
+
session:
|
38
|
+
name: "Nom d'utilisateur"
|
39
|
+
remember_me: "Se souvenir de moi"
|
40
|
+
password: "Mot de passe"
|
data/config/routes.rb
CHANGED
data/lib/snapuser.rb
CHANGED
data/lib/snapuser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snapuser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khcr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -87,7 +87,7 @@ files:
|
|
87
87
|
- app/views/sessions/new.html.erb
|
88
88
|
- app/views/users/_form.html.erb
|
89
89
|
- app/views/users/edit.html.erb
|
90
|
-
-
|
90
|
+
- config/locales/fr.yml
|
91
91
|
- config/routes.rb
|
92
92
|
- db/migrate/20150415193853_create_users.rb
|
93
93
|
- lib/snapuser.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
<% content_for :id, "profil" %>
|
2
|
-
|
3
|
-
<h1><%= t('user.index') %></h1>
|
4
|
-
|
5
|
-
<%= link_to t('user.edit.title'), user_edit_path if authorize_level?(2) %>
|
6
|
-
|
7
|
-
<div class="links">
|
8
|
-
<%= link_to_active "Home", root_path %>
|
9
|
-
<%= link_to_active t('user.index'), profile_path %>
|
10
|
-
<%= link_to_active t('layout.header.messages'), messages_path %>
|
11
|
-
<%= link_to_active t('layout.header.admin.files'), admin_files_path if authorize_level?(3) %>
|
12
|
-
<%= link_to_active t('layout.header.admin.pages'), admin_pages_path if authorize_level?(2) %>
|
13
|
-
<%= link_to_active t('layout.header.admin.events'), admin_events_path if authorize_level?(2) %>
|
14
|
-
<%= link_to_active t('layout.header.admin.activities'), admin_activities_path if authorize_level?(2) %>
|
15
|
-
<%= link_to_active t('layout.header.admin.galleries'), admin_galleries_path if authorize_level?(2) %>
|
16
|
-
<%= link_to_active t('layout.header.admin.messages'), admin_messages_path if authorize_level?(4) %>
|
17
|
-
<%= link_to_active t('layout.header.admin.newsletter_emails'), admin_newsletter_emails_path if authorize_level?(2) %>
|
18
|
-
<%= link_to_active t('layout.header.admin.downloads'), admin_downloads_path if authorize_level?(2) %>
|
19
|
-
<%= link_to_active t('layout.header.admin.users'), admin_users_path if authorize_level?(1) %>
|
20
|
-
</div>
|