def __init__(self, *args, **kwargs): super(CreateUserForm, self).__init__(*args, **kwargs) _password = Keystone.create_password() for field in ('password', 'password_confirm'): self.fields[field].initial = _password
def get(self, request, *args, **kwargs): context = {} try: user = self.keystone.return_find_u_user(kwargs.get('project_id')) new_password = Keystone.create_password() self.keystone.user_update(user, password=new_password) context = {'new_password': new_password} actionlog.log(request.user.username, 'update', user) except Exception as e: log.exception('{}{}'.format(_('Exception:').encode('UTF-8'), e)) return self.render_to_response(context, status=200)
def post(self, request, *args, **kwargs): project_id = request.POST.get('project') context, status = {}, 200 try: user = self.keystone.find_user_with_u_prefix(project_id, 'u') new_password = Keystone.create_password() self.keystone.user_update(user, password=new_password) context = {'new_password': new_password} actionlog.log(request.user.username, 'update', user) except Exception as e: context = {'msg': str(_('Error updating password'))} log.exception('Exception: {}'.format(e)) status = 500 return self.render_to_response(context, status=status)
def post(self, request, *args, **kwargs): project_id = request.POST.get("project") context, status = {}, 200 try: user = self.keystone.find_user_with_u_prefix(project_id, "u") new_password = Keystone.create_password() self.keystone.user_update(user, password=new_password) context = {"new_password": new_password} actionlog.log(request.user.username, "update", user) except Exception as e: context = {"msg": str(_("Error updating password"))} log.exception("Exception: {}".format(e)) status = 500 return self.render_to_response(context, status=status)
def test_create_password(self): computed = Keystone.create_password() self.assertTrue(isinstance(computed, str))