summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-08 22:35:10 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-04-08 22:35:10 +0300
commit4ca0bd3c78bb5e0e1b0ebfee31365ee10c16f277 (patch)
tree85842d2f28aa0e836620375d26fc0e22bacafe48
parentf3ef59c42cd17ebb6721d9c8106eca8d9826fcac (diff)
downloadgitlab-ci-4ca0bd3c78bb5e0e1b0ebfee31365ee10c16f277.tar.gz
Fix user profile update, show user gravatar
-rw-r--r--app/assets/stylesheets/main.scss15
-rw-r--r--app/controllers/users_controller.rb15
-rw-r--r--app/helpers/application_helper.rb6
-rw-r--r--app/views/layouts/application.html.haml20
4 files changed, 47 insertions, 9 deletions
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss
index 782daf4..d59d7a0 100644
--- a/app/assets/stylesheets/main.scss
+++ b/app/assets/stylesheets/main.scss
@@ -207,3 +207,18 @@ h3 {
font-weight: normal;
color: #666;
}
+
+.profile-holder {
+ position: relative;
+
+ img {
+ position: absolute;
+ top: -2px;
+ width: 24px;
+ @include border-radius(4px);
+ }
+
+ span {
+ margin-left: 35px;
+ }
+}
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index fa8ebdc..1c15aa0 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -16,9 +16,20 @@ class UsersController < ApplicationController
end
def update
- current_user.update_attributes(params[:user])
+ user_params = params[:user]
- redirect_to :back
+ if current_user.valid_password?(user_params.delete(:current_password))
+
+ user_params.delete(:password) if user_params[:password].blank?
+ user_params.delete(:password_confirmation) if user_params[:password_confirmation].blank?
+
+ current_user.update_attributes(user_params)
+
+ redirect_to :back
+ else
+
+ redirect_to :back, alert: 'Current password is invalid'
+ end
end
def destroy
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 51a7063..ff0b669 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -2,4 +2,10 @@ module ApplicationHelper
def loader_html
image_tag 'loader.gif'
end
+
+ def gravatar_icon(user_email = '', size = 40)
+ gravatar_url = 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=mm'
+ user_email.strip!
+ sprintf gravatar_url, hash: Digest::MD5.hexdigest(user_email.downcase), size: size
+ end
end
diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml
index 9d820b4..a03ef2e 100644
--- a/app/views/layouts/application.html.haml
+++ b/app/views/layouts/application.html.haml
@@ -20,20 +20,26 @@
= link_to 'Users', users_path
%li
= link_to 'Background Jobs', resque_path
+ %ul.nav.pull-right
+ - if current_user
%li
= link_to edit_user_path(current_user) do
- %i.icon-user.icon-white
- = current_user.email
+ .profile-holder
+ = image_tag gravatar_icon(current_user.email, 24)
+ %span= current_user.email
%li
- = link_to 'Logout', destroy_user_session_path, class: "logout", method: :delete
+ = link_to destroy_user_session_path, class: "logout", method: :delete do
+ %i.icon-signout
+ Logout
- else
%li
= link_to 'Login', new_user_session_path
.container-fluid
- - if alert || notice
- %small
- = alert || notice
- %hr
+ - if alert
+ .alert= alert
+ - if notice
+ .alert.alert-info= notice
+
= yield
.right
.padded