From ed90ef5b952ec6b49755f66230e8543ca52eb6be Mon Sep 17 00:00:00 2001 From: ultimatemember Date: Tue, 30 Dec 2014 20:18:29 +0200 Subject: [PATCH] Added Login Checks --- assets/css/um-fileupload.css | 25 ++++++++++++--- assets/css/um-profile.css | 12 ++++---- assets/css/um-responsive.css | 1 - assets/css/um-styles.css | 51 +++++++++++++++++++++--------- assets/js/um-modal.js | 23 ++++++++------ assets/js/um-responsive.js | 2 +- assets/js/um-scripts.js | 2 ++ core/um-actions-form.php | 2 ++ core/um-actions-login.php | 42 +++++++++++++++++++------ core/um-actions-misc.php | 33 ++++++++++++++------ core/um-actions-profile.php | 10 ++++++ core/um-fields.php | 60 ++++++++++++++++++++++++++++-------- core/um-files.php | 10 +++--- core/um-filters-fields.php | 55 +++++++++++++++++++++++++++------ core/um-form.php | 3 +- core/um-short-functions.php | 31 ++++++++++++++++--- core/um-user.php | 16 +++++++++- 17 files changed, 288 insertions(+), 90 deletions(-) diff --git a/assets/css/um-fileupload.css b/assets/css/um-fileupload.css index 1437fb01..deb61b5b 100644 --- a/assets/css/um-fileupload.css +++ b/assets/css/um-fileupload.css @@ -8,7 +8,7 @@ } .um .um-single-image-preview > img { - max-height: 200px; + max-height: 300px; display: block; overflow: hidden; margin: auto; @@ -22,6 +22,9 @@ position: relative; } +.um-single-image-preview.show, +.um-single-file-preview.show {display: block} + .um-single-image-preview > img { max-width: 100%; max-height: inherit; @@ -47,8 +50,14 @@ font-size: 16px; color: #888; position: relative; - top: 4px; + display: block; + width: 100%; + height: 100%; + line-height: 30px; + overflow: hidden; } +.um-single-image-preview a.cancel i:before, +.um-single-file-preview a.cancel i:before{line-height:inherit} /* - file info @@ -60,7 +69,7 @@ } .um-single-fileinfo span.icon { - font-size: 42px; + font-size: 40px; display: inline-block; width: 100px; height: 70px; @@ -68,13 +77,19 @@ background-color: #666; color: #fff !important; } -.um-single-fileinfo span.icon i{vertical-align: middle} +.um-single-fileinfo span.icon i { + display: block; + height: 70px; + line-height: 70px; + overflow: hidden; +} +.um-single-fileinfo span.icon i:before{line-height:inherit} .um-single-fileinfo span.filename { display: block; font-size: 16px; color: #888; - padding: 15px 0 0 0; + padding-top: 5px; } .um-single-fileinfo a { diff --git a/assets/css/um-profile.css b/assets/css/um-profile.css index fd3f40d2..b0d1a7d6 100644 --- a/assets/css/um-profile.css +++ b/assets/css/um-profile.css @@ -19,7 +19,7 @@ display: none; } -.um-profile img {display: block;overflow:hidden;border-radius:0!important;margin: 0!important} +.um-profile img {display: block;overflow:hidden;border-radius:0;margin: 0} .um-profile a, .um-profile a:hover {text-decoration:none !important} @@ -82,7 +82,7 @@ box-sizing: border-box; padding: 0 40px; color: #fff; - text-shadow: 0 2px #333; + text-shadow: 0 1px #666; cursor: pointer !important; line-height: 21px; font-size: 16px; @@ -200,17 +200,17 @@ position: absolute; top: 0; left: 0; - width: 100%; - height: 100%; background: rgba(0,0,0,.5); text-align: center; box-sizing: border-box; padding: 0 40px; color: #fff; + text-shadow: 0 1px #666; + cursor: pointer !important; line-height: 21px; font-size: 16px; - text-shadow: 0 1px #333; - cursor: pointer !important; + height: 100%; + width: 100%; } .um-profile-photo-overlay:hover { diff --git a/assets/css/um-responsive.css b/assets/css/um-responsive.css index 6c28150a..5b18d8c1 100644 --- a/assets/css/um-responsive.css +++ b/assets/css/um-responsive.css @@ -459,7 +459,6 @@ div.uimob800 .um-header .um-profile-meta { padding-left: 200px; } -div.uimob800 .um-cover-overlay span.um-cover-overlay-t, div.uimob800 .um-profile-photo-overlay span.um-profile-photo-overlay-t { display: none !important; diff --git a/assets/css/um-styles.css b/assets/css/um-styles.css index de3a7f66..214b2e53 100644 --- a/assets/css/um-styles.css +++ b/assets/css/um-styles.css @@ -155,6 +155,10 @@ p.um-notice.success { background: #7ACF58; } +p.um-notice.err { + background: #C74A4A; +} + /* - Errors */ @@ -276,19 +280,10 @@ p.um-notice.success { position: absolute; cursor: default; text-align: center !important; - top: 2px; - left: 2px; - width: 50px; - line-height: 34px; -} -.um-field-icon i:before { vertical-align: middle !important; margin: 0 auto !important; } - -.um-field-icon i { - font-size: 20px; - display: inline-block; - width: 100%; - height: 100%; - text-align: center; + top: 5px; + left: 0; + width: 44px; + font-size: 22px; } .um-form input[type=text], @@ -315,7 +310,7 @@ p.um-notice.success { } .um-form input[type=text].um-iconed, -.um-form input[type=password].um-iconed { padding-left: 50px } +.um-form input[type=password].um-iconed { padding-left: 44px } .um-form input[type=text].um-error, .um-form input[type=password].um-error { border-color: #C74A4A !important } @@ -550,4 +545,30 @@ a.um-link-alt:hover {text-decoration: underline !important;} width: 24px; height: 24px; z-index: 2; -} \ No newline at end of file +} + +/* + - Misc. +*/ + +div.um-photo { + margin: 20px auto 0 auto; + text-align: center; +} + +div.um-photo, +div.um-photo a, +div.um-photo img { + border-radius: 3px; +} + +div.um-photo a { + border: 1px solid #e5e5e5; + padding: 5px; + box-sizing: border-box; + display: inline-block; + box-shadow: 0 1px 1px #eee; + margin: 0 auto; +} + +div.um-photo img {max-height: 300px} \ No newline at end of file diff --git a/assets/js/um-modal.js b/assets/js/um-modal.js index 3c01d6b9..61510512 100644 --- a/assets/js/um-modal.js +++ b/assets/js/um-modal.js @@ -1,8 +1,8 @@ function initCrop_UM() { // only when a crop image is in view - var target_img = jQuery('.um-modal:visible .um-single-image-preview.crop img'); - var target_img_parent = jQuery('.um-modal:visible .um-single-image-preview.crop'); + var target_img = jQuery('.um-modal:visible .um-single-image-preview img'); + var target_img_parent = jQuery('.um-modal:visible .um-single-image-preview'); var crop_data = target_img.parent().attr('data-crop'); var min_width = target_img.parent().attr('data-min_width'); @@ -21,10 +21,8 @@ function initCrop_UM() { if ( target_img.attr('src') != '' ) { var max_height = jQuery(window).height() - ( jQuery('.um-modal-footer a').height() + 20 ) - 50 - ( jQuery('.um-modal-header:visible').height() ); - target_img.css({'height' : 'auto'}); target_img_parent.css({'height' : 'auto'}); - if ( jQuery(window).height() <= 400 ) { target_img_parent.css({ 'height': max_height +'px', 'max-height' : max_height + 'px' }); target_img.css({ 'height' : 'auto' }); @@ -32,7 +30,7 @@ function initCrop_UM() { target_img.css({ 'height': 'auto', 'max-height' : max_height + 'px' }); target_img_parent.css({ 'height': target_img.height(), 'max-height' : max_height + 'px' }); } - + if ( crop_data == 'square' ) { var opts = { @@ -63,7 +61,7 @@ function initCrop_UM() { } }; - } else { + } else if ( crop_data == 'user' ) { var opts = { dragCrop: true, @@ -78,7 +76,9 @@ function initCrop_UM() { } - target_img.cropper( opts ); + if ( crop_data != 0 ) { + target_img.cropper( opts ); + } } } @@ -162,7 +162,7 @@ function um_modal_responsive() { function um_remove_modal(){ - jQuery('.um-single-image-preview img').cropper("destroy"); + jQuery('.um-modal .um-single-image-preview img').cropper("destroy"); jQuery('body,html').css("overflow", "auto"); @@ -229,7 +229,7 @@ jQuery(document).ready(function() { var parent = jQuery(this).parents('.um-modal-body'); - parent.find('.um-single-image-preview img').cropper("destroy"); + parent.find('.um-modal .um-single-image-preview img').cropper("destroy"); parent.find('.um-single-image-preview img').attr('src', ''); @@ -258,6 +258,8 @@ jQuery(document).ready(function() { jQuery('.um-single-file-preview[data-key='+key+']').parents('.um-field').find('.um-btn-auto-width').html( jQuery(this).attr('data-change') ); + jQuery('.um-single-file-preview[data-key='+key+']').parents('.um-field').find('input[type=hidden]').val( jQuery('.um-single-file-preview[data-key='+key+']').parents('.um-field').find('.um-single-fileinfo a').attr('href') ); + }); /** @@ -317,6 +319,9 @@ jQuery(document).ready(function() { jQuery('.um-single-image-preview[data-key='+key+']').fadeIn().find('img').attr('src', src + "?"+d.getTime()); um_remove_modal(); jQuery('.um-single-image-preview[data-key='+key+']').parents('.um-field').find('.um-btn-auto-width').html( elem.attr('data-change') ); + + jQuery('.um-single-image-preview[data-key='+key+']').parents('.um-field').find('input[type=hidden]').val( src ); + } diff --git a/assets/js/um-responsive.js b/assets/js/um-responsive.js index 3ab010c0..9db34d8f 100644 --- a/assets/js/um-responsive.js +++ b/assets/js/um-responsive.js @@ -146,7 +146,7 @@ jQuery(window).load(function() { /* Run only when window is resized */ jQuery(window).resize(function() { - jQuery('.um-single-image-preview.crop:visible img').cropper("destroy"); + jQuery('.um-modal .um-single-image-preview.crop:visible img').cropper("destroy"); um_responsive(); um_modal_responsive(); diff --git a/assets/js/um-scripts.js b/assets/js/um-scripts.js index be100634..7a279621 100644 --- a/assets/js/um-scripts.js +++ b/assets/js/um-scripts.js @@ -126,6 +126,7 @@ jQuery(document).ready(function() { var parent = jQuery(this).parents('.um-field'); parent.find('.um-single-image-preview').hide(); parent.find('.um-btn-auto-width').html('Upload'); + parent.find('input[type=hidden]').val(''); return false; }); @@ -135,6 +136,7 @@ jQuery(document).ready(function() { var parent = jQuery(this).parents('.um-field'); parent.find('.um-single-file-preview').hide(); parent.find('.um-btn-auto-width').html('Upload'); + parent.find('input[type=hidden]').val(''); return false; }); diff --git a/core/um-actions-form.php b/core/um-actions-form.php index 2e88d857..71cf1179 100644 --- a/core/um-actions-form.php +++ b/core/um-actions-form.php @@ -51,6 +51,8 @@ do_action('um_submit_form_errors_hook_login', $args ); + do_action('um_submit_form_errors_hook_logincheck', $args ); + } else { do_action('um_submit_form_errors_hook_', $args ); diff --git a/core/um-actions-login.php b/core/um-actions-login.php index 07ca5ab4..e0dbb759 100644 --- a/core/um-actions-login.php +++ b/core/um-actions-login.php @@ -62,7 +62,6 @@ switch( $err ) { default: - break; case 'incorrect_password': @@ -78,6 +77,37 @@ } + /*** + *** @login checks + ***/ + add_action('um_submit_form_errors_hook_logincheck', 'um_submit_form_errors_hook_logincheck', 9999 ); + function um_submit_form_errors_hook_logincheck($args){ + global $ultimatemember; + + // Logout if logged in + if ( is_user_logged_in() ) { + wp_logout(); + } + + $user_id = ( isset( $ultimatemember->login->auth_id ) ) ? $ultimatemember->login->auth_id : ''; + um_fetch_user( $user_id ); + + $status = um_user('account_status'); // account status + switch( $status ) { + + // If user can't login to site... + case 'inactive': + case 'awaiting_admin_review': + case 'awaiting_email_confirmation': + case 'rejected': + um_reset_user(); + exit( wp_redirect( add_query_arg( 'err', $status, $ultimatemember->permalinks->get_current_url() ) ) ); + break; + + } + + } + /*** *** @login user ***/ @@ -85,16 +115,8 @@ function um_user_login($args){ global $ultimatemember; extract( $args ); - - if ( is_user_logged_in() ) { - wp_logout(); - } - $user_id = $ultimatemember->login->auth_id; - - um_fetch_user( $user_id ); - - $ultimatemember->user->auto_login( $user_id ); + $ultimatemember->user->auto_login( um_user('ID') ); // Priority redirect if ( isset( $args['redirect_to'] ) ) { diff --git a/core/um-actions-misc.php b/core/um-actions-misc.php index 7d102ad0..518a5c39 100644 --- a/core/um-actions-misc.php +++ b/core/um-actions-misc.php @@ -49,22 +49,37 @@ function um_add_update_notice($args){ global $ultimatemember; extract($args); + $output = ''; + if ( isset( $_REQUEST['updated'] ) && !empty( $_REQUEST['updated'] ) ) { - switch( $_REQUEST['updated'] ) { - case 'password_changed': - $msg = __('You have successfully changed your password.','ultimatemember'); + $success = __('You have successfully changed your password.','ultimatemember'); break; - } - } - if ( isset( $msg ) ) { - - echo '

' . $msg . '

'; - + if ( isset( $_REQUEST['err'] ) && !empty( $_REQUEST['err'] ) ) { + switch( $_REQUEST['err'] ) { + case 'inactive': + $err = __('Your account has been disabled.','ultimatemember'); + break; + case 'awaiting_admin_review': + $err = __('Your account has not been approved yet.','ultimatemember'); + break; + case 'awaiting_email_confirmation': + $err = __('Your account is awaiting e-mail verifications.','ultimatemember'); + break; + case 'rejected': + $err = __('Your membership request has been rejected.','ultimatemember'); + break; + } } + if ( isset( $err ) ) { + $output .= '

' . $err . '

'; + } + + echo $output; + } \ No newline at end of file diff --git a/core/um-actions-profile.php b/core/um-actions-profile.php index c5f78c2f..bfe8a4f7 100644 --- a/core/um-actions-profile.php +++ b/core/um-actions-profile.php @@ -261,6 +261,7 @@ global $ultimatemember; $to_update = null; + $files = null; if ( isset( $args['user_id'] ) ) { if ( um_can_edit_profile( $args['user_id'] ) ) { @@ -289,6 +290,11 @@ } else if ( $args['submitted'][$key] ) { $to_update[ $key ] = $args['submitted'][ $key ]; } + + // files + if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array('image','file') ) && um_is_temp_upload( $args['submitted'][ $key ] ) ) { + $files[ $key ] = $args['submitted'][ $key ]; + } } } @@ -296,6 +302,10 @@ if ( is_array( $to_update ) ) { $ultimatemember->user->update_profile( $to_update ); } + + if ( is_array( $files ) ) { + $ultimatemember->user->update_files( $files ); + } do_action('um_user_after_updating_profile', $to_update ); diff --git a/core/um-fields.php b/core/um-fields.php index 93e18b2b..5938e1dd 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -308,6 +308,8 @@ class UM_Fields { function field_value( $key, $default = false, $data = null ) { global $ultimatemember; + $type = (isset($data['type']))?$data['type']:''; + // preview in backend if ( isset( $ultimatemember->user->preview ) && $ultimatemember->user->preview ) { $submitted = um_user('submitted'); @@ -336,6 +338,7 @@ class UM_Fields { $value = um_user( $key ); $value = apply_filters("um_profile_field_filter_hook__", $value, $data ); $value = apply_filters("um_profile_field_filter_hook__{$key}", $value, $data ); + $value = apply_filters("um_profile_field_filter_hook__{$type}", $value, $data ); return $value; @@ -1002,19 +1005,33 @@ class UM_Fields { case 'image': $output .= '
'; + $output .= ''; + if ( isset( $data['label'] ) ) { - $output .= $this->field_label($label, $key, $data); + $output .= $this->field_label($label, $key, $data); } $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __('Upload Photo','ultimatemember'); + + $output .= '
'; - $output .= '
+ if ( $this->field_value( $key, $default, $data ) ) { -
+ $output .= '
+ + +
'. __('Change photo') . ''; - '. $button_text . ' + } else { + + $output .= '
+ + +
'. $button_text . ''; -
'; + } + + $output .= '
'; /* modal hidden */ $output .= '
'; @@ -1060,21 +1077,38 @@ class UM_Fields { case 'file': $output .= '
'; + $output .= ''; + if ( isset( $data['label'] ) ) { $output .= $this->field_label($label, $key, $data); } $modal_label = ( isset( $data['label'] ) ) ? $data['label'] : __('Upload Photo','ultimatemember'); - $output .= '
+ $output .= '
'; -
+ if ( $this->field_value( $key, $default, $data ) ) { + + $extension = pathinfo( $this->field_value( $key, $default, $data ), PATHINFO_EXTENSION); + + $output .= ''. __('Change file') . ''; + + } else { + + $output .= '
+
'. $button_text . ''; + + } -
- - '. $button_text . ' - -
'; + $output .= '
'; /* modal hidden */ $output .= '
'; @@ -1094,7 +1128,7 @@ class UM_Fields { $output .= '
- + diff --git a/core/um-files.php b/core/um-files.php index f4b631d4..39f2ec56 100644 --- a/core/um-files.php +++ b/core/um-files.php @@ -411,8 +411,8 @@ class UM_Files { $ext = '.' . pathinfo($source_name, PATHINFO_EXTENSION); $name = str_replace( $ext, '', $source_name ); $filename = $name . $ext; - - // copy image + + // copy file copy( $source, $this->upload_basedir . $user_id . '/' . $filename ); // thumbs @@ -466,15 +466,15 @@ class UM_Files { } } - + // clean up temp $dir = dirname( $source ); unlink( $source ); rmdir( $dir ); - + // update user's meta update_user_meta( $user_id, $key, $filename ); - + // the url of upload return $this->upload_baseurl . $user_id . '/' . $filename; diff --git a/core/um-filters-fields.php b/core/um-filters-fields.php index 64f54181..268c8990 100644 --- a/core/um-filters-fields.php +++ b/core/um-filters-fields.php @@ -1,5 +1,49 @@ + +
'; + } + + return $value; + } + + /*** + *** @Files + ***/ + add_filter('um_profile_field_filter_hook__image', 'um_profile_field_filter_hook__image', 99, 2); + function um_profile_field_filter_hook__image( $value, $data ) { + + $uri = um_user_uploads_uri() . $value; + $title = ( isset( $data['title'] ) ) ? $data['title'] : __('Untitled photo'); + + if ( !file_exists( um_user_uploads_dir() . $value ) ) { + $value = __('Image has been removed.'); + } else { + $value = '
'.$title.'
'; + } + + return $value; + } + /*** *** @some required changes before value is shown ***/ @@ -9,7 +53,6 @@ if ( isset( $data['validate'] ) && $data['validate'] != '' && strstr( $data['validate'], 'url' ) ) { $alt = ( isset( $data['url_text'] ) ) ? $data['url_text'] : $value; $url_rel = ( isset( $data['url_rel'] ) ) ? 'rel="nofollow"' : ''; - if( !strstr( $value, 'http' ) && !strstr( $value, '://' ) && !strstr( $value, 'www.' ) @@ -17,32 +60,24 @@ && !strstr( $value, '.net' ) && !strstr( $value, '.org' ) ) { - if ( $data['validate'] == 'facebook_url' ) $value = 'http://facebook.com/' . $value; if ( $data['validate'] == 'twitter_url' ) $value = 'http://twitter.com/' . $value; if ( $data['validate'] == 'linkedin_url' ) $value = 'http://linkedin.com/' . $value; if ( $data['validate'] == 'skype' ) $value = 'http://skype.com/' . $value; if ( $data['validate'] == 'googleplus_url' ) $value = 'http://plus.google.com/' . $value; - if ( $data['validate'] == 'instagram_url' ) $value = 'http://instagram.com/' . $value; - + if ( $data['validate'] == 'instagram_url' ) $value = 'http://instagram.com/' . $value; } - if ( strpos($value, 'http://') !== 0 ) { $value = 'http://' . $value; } - $value = ''.$alt.''; } if ( !is_array( $value ) ) { - if ( is_email( $value ) ) $value = ''.$value.''; - } else { - $value = implode(', ', $value); - } return $value; diff --git a/core/um-form.php b/core/um-form.php index a27013e0..36fd4efc 100644 --- a/core/um-form.php +++ b/core/um-form.php @@ -12,7 +12,7 @@ class UM_Form { $this->errors = null; - add_action('init', array(&$this, 'form_init'), 1); + add_action('init', array(&$this, 'form_init'), 2); add_action('init', array(&$this, 'field_declare'), 10); @@ -88,6 +88,7 @@ class UM_Form { do_action("um_submit_form_errors_hook", $this->post_form ); + do_action("um_submit_form_{$this->post_form['mode']}", $this->post_form ); } diff --git a/core/um-short-functions.php b/core/um-short-functions.php index e5680e8a..2aa682cb 100644 --- a/core/um-short-functions.php +++ b/core/um-short-functions.php @@ -13,6 +13,21 @@ return 0; } + + /*** + *** @Check that temp upload is valid + ***/ + function um_is_temp_upload( $url ) { + global $ultimatemember; + $url = explode('/ultimatemember/temp/', $url); + if ( isset( $url[1] ) ) { + $src = $ultimatemember->files->upload_temp . $url[1]; + if ( !file_exists( $src ) ) + return false; + return $src; + } + return false; + } /*** *** @Check that temp image is valid @@ -21,16 +36,12 @@ global $ultimatemember; $url = explode('/ultimatemember/temp/', $url); if ( isset( $url[1] ) ) { - $src = $ultimatemember->files->upload_temp . $url[1]; - if ( !file_exists( $src ) ) return false; - list($width, $height, $type, $attr) = @getimagesize($src); if ( isset( $width ) && isset( $height ) ) return $src; - } return false; } @@ -440,6 +451,18 @@ return $uri; } + /*** + *** @user uploads directory + ***/ + function um_user_uploads_dir() { + global $ultimatemember; + $uri = $ultimatemember->files->upload_basedir . um_user('ID') . '/'; + return $uri; + } + + /*** + *** @find closest number in an array + ***/ function um_closest_num($array, $number) { sort($array); foreach ($array as $a) { diff --git a/core/um-user.php b/core/um-user.php index caaaa6bb..7e6c39d1 100644 --- a/core/um-user.php +++ b/core/um-user.php @@ -21,7 +21,7 @@ class UM_User { $this->preview = false; - // needs to be updated by wp_update_user() + // a list of keys that should be done on wp_update_user $this->update_user_keys = array( 'user_email', 'user_pass', @@ -406,6 +406,20 @@ class UM_User { return false; } + /*** + *** @update files + ***/ + function update_files( $array ) { + + global $ultimatemember; + + foreach( $array as $key => $uri ) { + $src = um_is_temp_upload( $uri ); + $ultimatemember->files->new_user_upload( $this->id, $src, $key ); + } + + } + /*** *** @update profile ***/