def settings(request): """ View configuration for the personal settings view. Only logged in user can reach this page. :param request: current request of the server :return: dictionary with title and project name as well as a value, weather the user is logged in """ LOG.debug("Show settings %s", request.params) ui_locales = get_language_from_cookie(request) old_pw, new_pw, confirm_pw, message = '', '', '', '' success, error = False, False db_user: User = request.validated['user'] if 'form.passwordchange.submitted' in request.params: old_pw = escape_string(request.params['passwordold']) new_pw = escape_string(request.params['password']) confirm_pw = escape_string(request.params['passwordconfirm']) message, success = change_password(db_user, old_pw, new_pw, confirm_pw, ui_locales) error = not success settings_dict = DictionaryHelper(ui_locales).prepare_settings_dict(success, old_pw, new_pw, confirm_pw, error, message, db_user, request.application_url, request.decorated['extras']['use_with_ldap']) prep_dict = main_dict(request, Translator(ui_locales).get(_.settings)) prep_dict.update({ 'settings': settings_dict }) return prep_dict
def test_change_password(self): pascal = DBDiscussionSession.query(User).filter_by( nickname='Pascal').first() old_pw = 'iamatestuser2016' new_pw = 'iamatestuser2017' msg, success = user.change_password(pascal, old_pw, old_pw, old_pw, 'en') self.assertFalse(success) msg, success = user.change_password(pascal, old_pw, old_pw, new_pw, 'en') self.assertFalse(success) msg, success = user.change_password(pascal, old_pw, new_pw, old_pw, 'en') self.assertFalse(success) msg, success = user.change_password(pascal, new_pw, new_pw, old_pw, 'en') self.assertFalse(success) msg, success = user.change_password(pascal, new_pw, old_pw, old_pw, 'en') self.assertFalse(success) msg, success = user.change_password(pascal, old_pw, new_pw, new_pw, 'en') self.assertTrue(success) msg, success = user.change_password(pascal, new_pw, old_pw, old_pw, 'en') self.assertTrue(success)
def change_password(self): _t = Translator('en') msg1, success1 = user.change_password(self.user_tobi, None, 'tobiass', 'tobias', 'en') # not old pw msg2, success2 = user.change_password(self.user_tobi, 'tobias', None, 'tobias', 'en') # not new pw msg3, success3 = user.change_password(self.user_tobi, 'tobias', 'tobiass', None, 'en') # not confirm_pw msg4, success4 = user.change_password(self.user_tobi, 'tobias', 'tobias1', 'tobias2', 'en') # not new == confirm msg5, success5 = user.change_password(self.user_tobi, 'tobias', 'tobias', 'tobias', 'en') # old == new msg6, success6 = user.change_password(self.user_tobi, 'tobiaS', 'tobiass', 'tobias', 'en') # old wrong msg7, success7 = user.change_password(self.user_tobi, 'tobias', '123456', '123456', 'en') msg8, success8 = user.change_password(self.user_tobi, '123456', 'tobias', 'tobias', 'en') self.assertFalse(success1) self.assertFalse(success2) self.assertFalse(success3) self.assertFalse(success4) self.assertFalse(success5) self.assertFalse(success6) self.assertTrue(success7) self.assertTrue(success8) self.assertEquals(msg1, _t.get(_.oldPwdEmpty)) self.assertEquals(msg2, _t.get(_.newPwdEmtpy)) self.assertEquals(msg3, _t.get(_.confPwdEmpty)) self.assertEquals(msg4, _t.get(_.newPwdNotEqual)) self.assertEquals(msg5, _t.get(_.pwdsSame)) self.assertEquals(msg6, _t.get(_.oldPwdWrong)) self.assertEquals(msg7, _t.get(_.pwdChanged)) self.assertEquals(msg8, _t.get(_.pwdChanged))
def change_password(self): db_user = DBDiscussionSession.query(User).filter_by( nickname=str('Tobias')).first() _t = Translator('en') msg1, success1 = user.change_password(db_user, None, 'tobiass', 'tobias', 'en') # not old pw msg2, success2 = user.change_password(db_user, 'tobias', None, 'tobias', 'en') # not new pw msg3, success3 = user.change_password(db_user, 'tobias', 'tobiass', None, 'en') # not confirm_pw msg4, success4 = user.change_password(db_user, 'tobias', 'tobias1', 'tobias2', 'en') # not new == confirm msg5, success5 = user.change_password(db_user, 'tobias', 'tobias', 'tobias', 'en') # old == new msg6, success6 = user.change_password(db_user, 'tobiaS', 'tobiass', 'tobias', 'en') # old wrong msg7, success7 = user.change_password(db_user, 'tobias', '123456', '123456', 'en') msg8, success8 = user.change_password(db_user, '123456', 'tobias', 'tobias', 'en') self.assertFalse(success1) self.assertFalse(success2) self.assertFalse(success3) self.assertFalse(success4) self.assertFalse(success5) self.assertFalse(success6) self.assertTrue(success7) self.assertTrue(success8) self.assertEquals(msg1, _t.get(_.oldPwdEmpty)) self.assertEquals(msg2, _t.get(_.newPwdEmtpy)) self.assertEquals(msg3, _t.get(_.confPwdEmpty)) self.assertEquals(msg4, _t.get(_.newPwdNotEqual)) self.assertEquals(msg5, _t.get(_.pwdsSame)) self.assertEquals(msg6, _t.get(_.oldPwdWrong)) self.assertEquals(msg7, _t.get(_.pwdChanged)) self.assertEquals(msg8, _t.get(_.pwdChanged))