def handle(self, request, context): id = context.get('id', None) email = context.get('email',None) password = context.get('new_password',None) old_password = context.get('old_password',None) oldpassword = context.get('oldpassword',None) try: if password != '': encrypted_pwd = make_password(password) if check_password(old_password,oldpassword): user_pwd = User.objects(id = id).update(set__password = encrypted_pwd) else: return False if email is not None: try: email_name, domain_part = email.strip().split('@', 1) except ValueError: pass else: email = '@'.join([email_name, domain_part.lower()]) user_email = User.objects(id = id).update(set__email = email) return True except Exception,e: messages.error(request,_(e.message)) LOG.error(e.message)
def handle(self, request, context): id = context.get('id', None) roles = context.get('role', None) try: for i in roles: User.objects(id=id).update(pull__roles=i) return True except Exception,e: messages.error(request,_(e.message)) LOG.error(e.message)
def get_initial(self): id = self.kwargs["user_id"] user = User.objects(id = id).first() username = user.username email = user.email old_password = user.password return {'id':id,'username':username,'email':email,'oldpassword':old_password}
def populate_roles_choices(self, request, context): try: id = context['id'] rolelist = [] success = [] user_rolelist = User.objects(id=id).first() if request.user.roles: for role in request.user.roles: if (role.name == "Tenant Admin") & (role.roletype == "Tenant Admin"): success.append("Tenant Admin") else: success.append("Member") aval_rolelist = roledetail.objects(tenantid=request.user.tenantid.id) if "Tenant Admin" in success: for i in aval_rolelist: if i in user_rolelist.roles: rolelist.append(i) else: pass else: for i in aval_rolelist: if i in user_rolelist.roles: if i.roletype == "Tenant Admin": pass else: rolelist.append(i) else: pass roles = [(role.id, role.name) for role in rolelist] except Exception, e: messages.error(request,_(e.message)) LOG.error(e.message) roles = []
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): # To Create master collections when first tenant sign up tenant = Tenant.objects.all() if tenant.count() == 0: create_master_db_schema() username = form.data['username'] password = form.data['password1'] email = form.data['email'] time = datetime.now().isoformat() plain = username + '\0' + time token = sha1(plain).hexdigest() tenant = Tenant(name=username) tenant.save() role_access = roleaccess.objects.all() access = role_access[0].access access.append("Edit User") envi1 = roledetail(roletype="Tenant Admin", name="Tenant Admin", policy=[], access=access, tenantid=tenant.id) envi1.save() envi = User.create_user(username=email.lower(), email=email, password=password, roles=[envi1.id], key=token, tenantid=tenant.id, hp_attr=None) envi.save() t = loader.get_template("activation_email.txt") c = Context({ 'name': username, 'activation_key': token, 'email': email, 'product_url': "http://" + request.META["HTTP_HOST"] + "/signup/activate", }) m = Mail(email) m.send_mail(t.render(c)) return HttpResponseRedirect('/signup/success') else: form = RegistrationForm() variables = RequestContext(request, {'form': form}) return render_to_response( 'register.html', variables, )
def handle(self, request, context): id = context.get('id', None) password = context.get('new_password',None) try: if password is not None: encrypted_pwd = make_password(password) user_pwd = User.objects(id = id).update(set__password = encrypted_pwd) return True except Exception,e: messages.error(request,_(e.message)) LOG.error(e.message)
def action(self, request, obj_id): try: role = roledetail.objects(id=obj_id).first() users = User.objects.all() for user in users: if len(user.roles) == 1: for roles in user.roles: if roles.id == role.id: raise Exception( "Role can't be delete. Some users have this role only. Remove them first..." ) for user in users: role_list = [] for roles in user.roles: if roles.id == role.id: pass else: role_list.append(roles) User.objects(id=user.id).update(set__roles=role_list) role.delete() except Exception, e: messages.info(request, _(e.message)) exceptions.handle_redirect(request, self.success_url)
def get_data(self): # Add data to the context here... if "Tenant Admin" not in self.request.session['user_roles']: refresh_session_policies(self.request, self.request.user) obj = User.objects(tenantid=self.request.user.tenantid.id) users = [] for user in obj: role_name = "" for a in user.roles: role = roledetail.objects(id=a.id).first() role_name = role_name + role.name+"," tet_obj = UserObj(user.id,user.username,role_name[:-1]) users.append(tet_obj) return users
def action(self, request, obj_id): try: role = roledetail.objects(id=obj_id).first() users = User.objects.all() for user in users: if (len(user.roles) == 1): for roles in user.roles: if roles.id == role.id: raise Exception( "Role can't be delete. Some users have this role only. Remove them first..." ) for user in users: role_list = [] for roles in user.roles: if roles.id == role.id: pass else: role_list.append(roles) User.objects(id=user.id).update(set__roles=role_list) role.delete() except Exception, e: messages.info(request, _(e.message)) exceptions.handle_redirect(request, self.success_url)
def register(request): if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): # To Create master collections when first tenant sign up tenant = Tenant.objects.all() if tenant.count() == 0: create_master_db_schema() username=form.data['username'] password=form.data['password1'] email=form.data['email'] time = datetime.now().isoformat() plain = username + '\0' + time token = sha1(plain).hexdigest() tenant = Tenant(name=username) tenant.save() role_access = roleaccess.objects.all() access = role_access[0].access access.append("Edit User") envi1 = roledetail(roletype = "Tenant Admin",name="Tenant Admin", policy=[], access=access, tenantid=tenant.id) envi1.save() envi = User.create_user(username=email.lower(),email=email, password=password, roles=[envi1.id], key=token, tenantid=tenant.id,hp_attr = None) envi.save() t = loader.get_template("activation_email.txt") c = Context({'name': username, 'activation_key' : token, 'email' : email, 'product_url' : "http://" + request.META["HTTP_HOST"] + "/signup/activate", }) m = Mail(email) m.send_mail(t.render(c)) return HttpResponseRedirect('/signup/success') else: form = RegistrationForm() variables = RequestContext(request, { 'form': form }) return render_to_response( 'register.html', variables, )
def handle(self, request, context): username = context.get('username', None) roles = context.get('role', None) email = context.get('email', None) password = context.get('password', None) try: time = datetime.now().isoformat() plain = username + '\0' + time activation_key = sha1(plain).hexdigest() tenant_db = User.create_user(username=username.lower(), password= password, roles = roles,email = email, tenantid=request.user.tenantid,key=activation_key) tenant_db.save() t = loader.get_template("activation_email.txt") c = Context({'name': username, 'activation_key' : activation_key, 'email' : email, 'product_url' : "http://" + request.META["HTTP_HOST"] + "/signup/activate", }) m = Mail(email) m.send_mail(t.render(c)) return True except Exception,e: messages.error(request,_(e.message)) LOG.error(e.message)
def action(self, request, obj_id): user = User.objects(id=obj_id) user.delete()
def get_initial(self): id = self.kwargs["user_id"] user = User.objects(id = id).first() username = user.username return {'id':id,'username':username}
def action(self, request, obj_id): user = User.objects(id = obj_id) user.delete()