diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/stylesheets/leap.scss | 3 | ||||
-rw-r--r-- | app/controllers/sessions_controller.rb | 9 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 6 | ||||
-rw-r--r-- | app/models/invite_code.rb | 1 | ||||
-rw-r--r-- | app/models/invite_code_validator.rb | 7 | ||||
-rw-r--r-- | app/views/users/_user.html.haml | 34 | ||||
-rw-r--r-- | app/views/users/index.html.haml | 3 |
7 files changed, 54 insertions, 9 deletions
diff --git a/app/assets/stylesheets/leap.scss b/app/assets/stylesheets/leap.scss index dddcc1a..9fe2195 100644 --- a/app/assets/stylesheets/leap.scss +++ b/app/assets/stylesheets/leap.scss @@ -307,3 +307,6 @@ html, body { margin: 0 2px; } } +.modal-footer form{ + margin: 0; +} diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 66eba40..34d4f53 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -32,4 +32,13 @@ class SessionsController < ApplicationController # throw :warden, response.finish #end + Warden::Manager.after_set_user do |user, auth, opts| + scope = opts[:scope] + unless user.enabled? + auth.logout(scope) + throw(:warden, scope: scope, reason: "User not active") + end + end + + end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 3943afc..446b726 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -49,13 +49,15 @@ class UsersController < ApplicationController def deactivate @user.enabled = false @user.save - respond_with @user + flash[:notice] = I18n.t("actions.user_disabled_message", username: @user.username) + redirect_to :back end def enable @user.enabled = true @user.save - respond_with @user + flash[:notice] = I18n.t("actions.user_enabled_message", username: @user.username) + redirect_to :back end def destroy diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 30a6498..13c3a39 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -4,6 +4,7 @@ class InviteCode < CouchRest::Model::Base use_database 'invite_codes' property :invite_code, String, :read_only => true property :invite_count, Integer, :default => 0, :accessible => true + property :max_uses, Integer, :default => 1 timestamps! diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb index f96ca4a..676e4fa 100644 --- a/app/models/invite_code_validator.rb +++ b/app/models/invite_code_validator.rb @@ -1,4 +1,5 @@ class InviteCodeValidator < ActiveModel::Validator + def validate(user) user_invite_code = InviteCode.find_by_invite_code user.invite_code @@ -6,7 +7,7 @@ class InviteCodeValidator < ActiveModel::Validator if not_existent?(user_invite_code) add_error_to_user("This is not a valid code", user) - elsif count_greater_than_zero?(user_invite_code) + elsif has_no_uses_left?(user_invite_code) add_error_to_user("This code has already been used", user) end end @@ -16,8 +17,8 @@ class InviteCodeValidator < ActiveModel::Validator code == nil end - def count_greater_than_zero?(code) - code.invite_count > 0 + def has_no_uses_left?(code) + code.invite_count >= code.max_uses end def add_error_to_user(error, user) diff --git a/app/views/users/_user.html.haml b/app/views/users/_user.html.haml index 583d22f..1cabcf5 100644 --- a/app/views/users/_user.html.haml +++ b/app/views/users/_user.html.haml @@ -1,4 +1,32 @@ %tr - %td= link_to user.login, user - %td= l(user.created_at, :format => :short) - %td= l(user.updated_at, :format => :short) + %td + = link_to user.username, user + %td + = user.created_at.strftime("%d %b, %Y, %H:%M") + %td + = user.updated_at.strftime("%d %b, %Y, %H:%M") + %td + - if user.enabled + %button.btn.btn-default{:"data-toggle" => "modal", :"data-target" => "#user-form-#{user.id}", :type => "button"} + = t("actions.disable_user") + .modal.fade.hide{:id => "user-form-#{user.id}"} + .modal-dialog + .modal-content + .modal-header + %button.close{:"data-dismiss" => "modal"} × + = t("actions.confirm_user_deactivation", username: user.username) + .modal-footer + = form_tag deactivate_user_path(user) do + %input.btn.btn-default.btn-danger{:type => "submit", :value => "#{t("actions.disable_user")}"} + - else + %button.btn.btn-default{:"data-toggle" => "modal", :"data-target" => "#user-form-#{user.id}", :type => "button"} + = t("actions.enable_user") + .modal.fade.hide{:id => "user-form-#{user.id}"} + .modal-dialog + .modal-content + .modal-header + %button.close{:"data-dismiss" => "modal"} × + = t("actions.confirm_user_activation", username: user.username) + .modal-footer + = form_tag enable_user_path(user) do + %input.btn.btn-default.btn-danger{:type => "submit", :value => "#{t("actions.enable_user")}"} diff --git a/app/views/users/index.html.haml b/app/views/users/index.html.haml index 3ed8835..e1136d8 100644 --- a/app/views/users/index.html.haml +++ b/app/views/users/index.html.haml @@ -1,4 +1,5 @@ - @show_navigation = false = search :users -= table @users, %w(username, created, updated) += table @users, %w(username, created, updated, actions.toggle_user) + |