Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move password change to security settings #10053

Merged
merged 3 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/private/Settings/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private function getBuiltInPersonalSettings($section): array {
}
if($section === 'security') {
/** @var ISettings $form */
$form = new Personal\Security();
$form = new Personal\Security($this->userManager);
$forms[$form->getPriority()] = [$form];
}
if ($section === 'additional') {
Expand Down
1 change: 0 additions & 1 deletion lib/private/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function getForm() {
'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
'groups' => $this->getGroups($user),
'passwordChangeSupported' => $user->canChangePassword(),
] + $messageParameters + $languageParameters + $localeParameters;


Expand Down
19 changes: 18 additions & 1 deletion lib/private/Settings/Personal/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,33 @@


use OCP\AppFramework\Http\TemplateResponse;
use OCP\IUserManager;
use OCP\Settings\ISettings;

class Security implements ISettings {

private $userManager;

public function __construct(
IUserManager $userManager
) {
$this->userManager = $userManager;
}

/**
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
* @since 9.1
*/
public function getForm() {
return new TemplateResponse('settings', 'settings/personal/security');
$user = $this->userManager->get(\OC_User::getUser());
$passwordChangeSupported = false;
if ($user !== null) {
$passwordChangeSupported = $user->canChangePassword();
}

return new TemplateResponse('settings', 'settings/personal/security', [
'passwordChangeSupported' => $passwordChangeSupported
]);
}

/**
Expand Down
50 changes: 29 additions & 21 deletions settings/css/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ select {
}
}

input {
&#pass1,
&#pass2,
&#passwordbutton {
width: 100%;
}
}

#personal-settings {
display: grid;
padding: 20px;
Expand Down Expand Up @@ -380,9 +372,7 @@ input#identity {
}
}

.password-state {
display: inline-block;
}


table.nostyle {
label {
Expand All @@ -393,6 +383,33 @@ table.nostyle {
}
}

#security-password {
#passwordform {
display: flex;
flex-wrap: wrap;
#pass1, .personal-show-container, #passwordbutton {
flex-shrink: 1;
width: 200px;
min-width: 150px;
}
#pass2 {
width: 100%;
}
.password-state {
display: inline-block;
}
.strengthify-wrapper {
position: absolute;
left: 0;
width: 100%;
border-radius: 0 0 2px 2px;
margin-top: -6px;
overflow: hidden;
height: 3px;
}
}
}

#security {
table {
width: 100%;
Expand Down Expand Up @@ -1243,16 +1260,7 @@ span {
}
}

/* PASSWORD */
#passwordform .strengthify-wrapper {
position: absolute;
left: 0;
width: 100%;
border-radius: 0 0 2px 2px;
margin-top: -6px;
overflow: hidden;
height: 3px;
}


/* OPERA hack for strengthify*/
doesnotexist:-o-prefocus, .strengthify-wrapper {
Expand Down
85 changes: 85 additions & 0 deletions settings/js/security_password.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* global OC */

/**
* Copyright (c) 2011, Robin Appelman <[email protected]>
* 2013, Morris Jobke <[email protected]>
* 2016, Christoph Wurst <[email protected]>
* 2017, Arthur Schiwon <[email protected]>
* 2017, Thomas Citharel <[email protected]>
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file.
*/

$(document).ready(function () {
if($('#pass2').length) {
$('#pass2').showPassword().keyup();
}

var removeloader = function () {
setTimeout(function(){
if ($('.password-state').length > 0) {
$('.password-state').remove();
}
}, 5000)
};

$("#passwordbutton").click(function () {
if ($('#pass1').val() !== '' && $('#pass2').val() !== '') {
// Serialize the data
var post = $("#passwordform").serialize();
$('#passwordchanged').hide();
$('#passworderror').hide();
$("#passwordbutton").attr('disabled', 'disabled');
$("#passwordbutton").after("<span class='password-loading icon icon-loading-small-dark password-state'></span>");
$(".personal-show-label").hide();
// Ajax foo
$.post(OC.generateUrl('/settings/personal/changepassword'), post, function (data) {
if (data.status === "success") {
$("#passwordbutton").after("<span class='checkmark icon icon-checkmark password-state'></span>");
removeloader();
$('#pass1').val('');
$('#pass2').val('').change();
}
if (typeof(data.data) !== "undefined") {
OC.msg.finishedSaving('#password-error-msg', data);
} else {
OC.msg.finishedSaving('#password-error-msg',
{
'status' : 'error',
'data' : {
'message' : t('settings', 'Unable to change password')
}
}
);
}
$(".personal-show-label").show();
$(".password-loading").remove();
$("#passwordbutton").removeAttr('disabled');
});
return false;
} else {
OC.msg.finishedSaving('#password-error-msg',
{
'status' : 'error',
'data' : {
'message' : t('settings', 'Unable to change password')
}
}
);
return false;
}
});

$('#pass2').strengthify({
zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
titles: [
t('settings', 'Very weak password'),
t('settings', 'Weak password'),
t('settings', 'So-so password'),
t('settings', 'Good password'),
t('settings', 'Strong password')
],
drawTitles: true,
$addAfter: $('input[name="newpassword-clone"]'),
});
});
74 changes: 0 additions & 74 deletions settings/js/settings/personalInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,67 +145,6 @@ $(document).ready(function () {
$('#pass2').showPassword().keyup();
}

var removeloader = function () {
setTimeout(function(){
if ($('.password-state').length > 0) {
$('.password-state').remove();
}
}, 5000)
};

$("#passwordbutton").click(function () {
var isIE8or9 = $('html').hasClass('lte9');
// FIXME - TODO - once support for IE8 and IE9 is dropped
// for IE8 and IE9 this will check additionally if the typed in password
// is different from the placeholder, because in IE8/9 the placeholder
// is simply set as the value to look like a placeholder
if ($('#pass1').val() !== '' && $('#pass2').val() !== ''
&& !(isIE8or9 && $('#pass2').val() === $('#pass2').attr('placeholder'))) {
// Serialize the data
var post = $("#passwordform").serialize();
$('#passwordchanged').hide();
$('#passworderror').hide();
$("#passwordbutton").attr('disabled', 'disabled');
$("#passwordbutton").after("<span class='password-loading icon icon-loading-small-dark password-state'></span>");
$(".personal-show-label").hide();
// Ajax foo
$.post(OC.generateUrl('/settings/personal/changepassword'), post, function (data) {
if (data.status === "success") {
$("#passwordbutton").after("<span class='checkmark icon icon-checkmark password-state'></span>");
removeloader();
$('#pass1').val('');
$('#pass2').val('').change();
}
if (typeof(data.data) !== "undefined") {
OC.msg.finishedSaving('#password-error-msg', data);
} else {
OC.msg.finishedSaving('#password-error-msg',
{
'status' : 'error',
'data' : {
'message' : t('settings', 'Unable to change password')
}
}
);
}
$(".personal-show-label").show();
$(".password-loading").remove();
$("#passwordbutton").removeAttr('disabled');
});
return false;
} else {
OC.msg.finishedSaving('#password-error-msg',
{
'status' : 'error',
'data' : {
'message' : t('settings', 'Unable to change password')
}
}
);
return false;
}
});

var showVerifyDialog = function(dialog, howToVerify, verificationCode) {
var dialogContent = dialog.children('.verification-dialog-content');
dialogContent.children(".explainVerification").text(howToVerify);
Expand Down Expand Up @@ -417,19 +356,6 @@ $(document).ready(function () {
sendCropData();
});

$('#pass2').strengthify({
zxcvbn: OC.linkTo('core','vendor/zxcvbn/dist/zxcvbn.js'),
titles: [
t('settings', 'Very weak password'),
t('settings', 'Weak password'),
t('settings', 'So-so password'),
t('settings', 'Good password'),
t('settings', 'Strong password')
],
drawTitles: true,
$addAfter: $('input[name="newpassword-clone"]'),
});

// Load the big avatar
var user = OC.getCurrentUser();
$('#avatarform .avatardiv').avatar(user.uid, 145, true, null, function() {
Expand Down
32 changes: 0 additions & 32 deletions settings/templates/settings/personal/personal.info.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
'federationscopemenu',
'settings/personalInfo',
]);
vendor_script('strengthify/jquery.strengthify');
vendor_style('strengthify/strengthify');
vendor_script('jcrop/js/jquery.Jcrop');
vendor_style('jcrop/css/jquery.Jcrop');

Expand Down Expand Up @@ -376,36 +374,6 @@
</form>
<?php } ?>
</div>
<div class="personal-settings-setting-box personal-settings-password-box">
<?php
if($_['passwordChangeSupported']) {
script('jquery-showpassword');
?>
<form id="passwordform" class="section">
<h2 class="inlineblock"><?php p($l->t('Password'));?></h2>
<div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div>

<label for="pass1" class="hidden-visually"><?php p($l->t('Current password')); ?>: </label>
<input type="password" id="pass1" name="oldpassword"
placeholder="<?php p($l->t('Current password'));?>"
autocomplete="off" autocapitalize="none" autocorrect="off" />

<div class="personal-show-container">
<label for="pass2" class="hidden-visually"><?php p($l->t('New password'));?>: </label>
<input type="password" id="pass2" name="newpassword"
placeholder="<?php p($l->t('New password')); ?>"
data-typetoggle="#personal-show"
autocomplete="off" autocapitalize="none" autocorrect="off" />
<input type="checkbox" id="personal-show" name="show" /><label for="personal-show" class="personal-show-label"></label>
</div>

<input id="passwordbutton" type="submit" value="<?php p($l->t('Change password')); ?>" />

</form>
<?php
}
?>
</div>
<span class="msg"></span>
</div>

Expand Down
Loading