def create_acount_type(type_id, self, shib, host, sponsor, title, permanent, archive, depth, pages, default, adv, protected ): try: atype = AccountType.objects.get(type_id=type_id) print(" Updating Account Type: " + title) atype.type = type_id atype.title = title atype.self_registration = self atype.shibboleth = shib atype.self_hosted = host atype.sponsor = sponsor atype.max_archive = archive atype.max_permanent = permanent atype.max_depth = depth atype.max_pages = pages atype.default = default atype.advanced = adv atype.protected = protected except ObjectDoesNotExist: print(" Creating Account Type: " + title ) atype = AccountType(type_id=type_id, self_registration=self, shibboleth=shib, self_hosted=host, sponsor=sponsor, title=title, max_archive=archive, max_permanent=permanent, max_depth=depth, max_pages=pages, default=default, advanced=adv, protected=protected) atype.save() return atype
def register_new_user(request): json_obj=json.loads(request.body) json_obj=json_obj['userInfo'] if User.objects.filter(username = json_obj['userName']).exists(): print "Username already Exist." return HttpResponse(json.dumps({"validation":"Username is already exist.","status":False}), content_type="application/json") username = json_obj['userName'] first_name = json_obj['firstName'] last_name = json_obj['lastName'] password = json_obj['password'] password1 = json_obj['confirmPassword'] if password != password1: print "Passwords Are not Matching" return HttpResponse(json.dumps({"validation":"Passwords are not Matched","status":False}), content_type="application/json") email = validateEmail(json_obj['email']) if email != True: print "Email is already Exist." return HttpResponse(json.dumps({"validation":"Email is already exist.Try with another Email.","status":False}), content_type="application/json") else: email = json_obj['email'] if json_obj['addressLine1'] is None: return HttpResponse(json.dumps({"validation":"Please Enter Your Address...!","status":False}), content_type="application/json") else: address_line1 = json_obj['addressLine1'] address_line2 = json_obj['addressLine2'] contact_no = json_obj['mobileNo0'] contact_no = int(contact_no) contact_no = validate_mobile(str(contact_no)) if contact_no == False: return HttpResponse(json.dumps([{"validation": "This mobile number is already used..please try with another one.", "status": False}]), content_type = "application/json") else: contact_no1 = json_obj['mobileNo1'] city = json_obj['city'] state = json_obj['state'] country = json_obj['country'] pin_code = json_obj['pincode'] accounttype_obj = AccountType(optionType=1) accounttype_obj.save() group_obj_for_bank_acc = Group(optionType=0) group_obj_for_bank_acc.save() group_obj_for_cash_acc = Group(optionType=4) group_obj_for_cash_acc.save() bank_account_name = "My Bank Account" cash_account_name = "My Cash Account" bank_account_obj = Account(account_name=bank_account_name,first_name=first_name,last_name=last_name,contact_no=contact_no,address_line1=address_line1,city=city,state=state,country=country,pin_code=pin_code,accounttype=accounttype_obj,group=group_obj_for_bank_acc) bank_account_obj.save() cash_account_obj = Account(account_name=cash_account_name,first_name=first_name,last_name=last_name,contact_no=contact_no,address_line1=address_line1,city=city,state=state,country=country,pin_code=pin_code,accounttype=accounttype_obj,group=group_obj_for_cash_acc) cash_account_obj.save() user_obj = User(first_name=first_name,last_name=last_name,username=username,email=email,password=password) user_obj.set_password(password) user_obj.save() userdetail_obj = UserDetail(user=user_obj,address_line1=address_line1,address_line2=address_line2,contact_no=contact_no,city=city, state=state,country=country,pin_code=pin_code,contact_no1=contact_no1,bank_account=bank_account_obj,cash_account=cash_account_obj) userdetail_obj.save() print "Registration Successful" return HttpResponse(json.dumps({"validation":"Registration Successful.","redirecturl":"#/login","status":True}), content_type="application/json")
def setUp(self): self.user_1 = User.objects.create_user(username="******") self.user_2 = User.objects.create_user(username="******") self.account_a = Account.objects.create(name="account_a", type=AccountType.get("bronze")) self.account_a.address_add("a") self.account_b = Account.objects.create(name="account_b", type=AccountType.get("bronze")) self.account_b.address_add("b")
def setUp(self): self.account_a = Account.objects.create( name='account_a', type=AccountType.get('bronze') ) self.account_b = Account.objects.create( name='account_b', type=AccountType.get('gold') ) self.user_1 = User.objects.create(username='******') self.user_2 = User.objects.create(username='******')
def create_new_user_account(request): if request.user.is_authenticated(): print request.body print request.user json_obj = json.loads(request.body) accountInfo = json_obj['accountInfo'] account_name = accountInfo.get("account_name") alias = accountInfo.get("alias") group = accountInfo.get("group") grouptype = group.get("id") first_name = accountInfo.get("firstName") last_name = accountInfo.get("lastName") email = accountInfo.get("email") address_line1 = accountInfo.get("addressLine1") address_line2 = accountInfo.get("addressLine2") city = accountInfo.get("city") state = accountInfo.get("state") country = accountInfo.get("country") try: pin_code = accountInfo.get("pincode") except ValueError: return HttpResponse(json.dumps([{"validation": "Please Enter Valid PinCode.", "status": False}]), content_type = "application/json") contact_no = accountInfo.get("mobileNo0") contact_no1 = accountInfo.get("mobileNo1") opening_balance = accountInfo.get("openingBalance") accounttype = accountInfo.get("accounttype") accounttype = accounttype.get("id") user_obj = User.objects.get(id=request.user.id) accounttype_obj = AccountType(optionType=accounttype) accounttype_obj.save() group_obj = Group(optionType=grouptype) group_obj.save() account_obj = Account(first_name=first_name,last_name=last_name,email=email,address_line1=address_line1, city=city,state=state,country=country,pin_code=pin_code,contact_no=contact_no ,contact_no1=contact_no1,account_name=account_name,opening_balance=opening_balance,group=group_obj,accounttype=accounttype_obj) account_obj.save() userdetail_obj = UserDetail.objects.get(user__id=request.user.id) userdetail_obj.account.add(account_obj) userdetail_obj.save() return HttpResponse(json.dumps({"validation":"New Account created Successfully","status":True}), content_type="application/json") else: return HttpResponse(json.dumps({"validation":"You are not logged in yet.Please login to continue."}), content_type="application/json")
def setUp(self): self.user_1 = User.objects.create_user(username='******') self.user_2 = User.objects.create_user(username='******') self.user_3 = User.objects.create_user(username='******') self.account_1 = Account.objects.create( name='account_1', type=AccountType.get('bronze') ) self.account_1.owners.add(self.user_1) self.account_1.key_add( users=[self.user_3], scopes=[ (READ, 'aaa'), (UPDATE, 'aaa/bbb'), (CREATE, None, 'session') ] ) self.account_2 = Account.objects.create( name='account_2', type=AccountType.get('bronze') ) self.account_2.owners.add(self.user_2) self.address_1 = Address.objects.create( address='aaa', account=self.account_1 ) self.address_2 = Address.objects.create( address='aaa/bbb', account=self.account_1, public=True ) self.address_3 = Address.objects.create( address='bbb', account=self.account_2 )
def setUp(self): self.client = Client() self.user_1 = User.objects.create_user(username="******", password="******") self.user_2 = User.objects.create_user(username="******", password="******") self.account = Account.objects.create(name="account_a", type=AccountType.get("bronze")) self.account.address_add("a", public=True) self.account.address_add("b") key = self.account.keys.create(address="b", action=READ) key.users = [self.user_1] self.com_a = Component.objects.create(address="a") self.com_b = Component.objects.create(address="b")
def user_post_save(sender, instance, created, **kwargs): ''' Creates a UserDetails and a personal Account when a User is first created. ''' from accounts.models import Account, AccountType if created: user = instance guest = user.email=="guest" if not guest: account = Account.objects.create( name=user.username, type=AccountType.get('bronze'), personal=True ) account.owners.add(user) UserDetails.objects.create( user=user, guest=guest )
def create_new_user_account(request): if request.user.is_authenticated(): print request.body print request.user json_obj = json.loads(request.body) accountInfo = json_obj['accountInfo'] account_name = accountInfo.get("account_name") alias = accountInfo.get("alias") group = accountInfo.get("group") grouptype = group.get("id") first_name = accountInfo.get("firstName") last_name = accountInfo.get("lastName") email = accountInfo.get("email") address_line1 = accountInfo.get("addressLine1") address_line2 = accountInfo.get("addressLine2") city = accountInfo.get("city") state = accountInfo.get("state") country = accountInfo.get("country") try: pin_code = accountInfo.get("pincode") except ValueError: return HttpResponse(json.dumps([{ "validation": "Please Enter Valid PinCode.", "status": False }]), content_type="application/json") contact_no = accountInfo.get("mobileNo0") contact_no1 = accountInfo.get("mobileNo1") opening_balance = accountInfo.get("openingBalance") accounttype = accountInfo.get("accounttype") accounttype = accounttype.get("id") user_obj = User.objects.get(id=request.user.id) accounttype_obj = AccountType(optionType=accounttype) accounttype_obj.save() group_obj = Group(optionType=grouptype) group_obj.save() account_obj = Account(first_name=first_name, last_name=last_name, email=email, address_line1=address_line1, city=city, state=state, country=country, pin_code=pin_code, contact_no=contact_no, contact_no1=contact_no1, account_name=account_name, opening_balance=opening_balance, group=group_obj, accounttype=accounttype_obj) account_obj.save() userdetail_obj = UserDetail.objects.get(user__id=request.user.id) userdetail_obj.account.add(account_obj) userdetail_obj.save() return HttpResponse(json.dumps({ "validation": "New Account created Successfully", "status": True }), content_type="application/json") else: return HttpResponse(json.dumps({ "validation": "You are not logged in yet.Please login to continue." }), content_type="application/json")
def register_new_user(request): json_obj = json.loads(request.body) json_obj = json_obj['userInfo'] if User.objects.filter(username=json_obj['userName']).exists(): print "Username already Exist." return HttpResponse(json.dumps({ "validation": "Username is already exist.", "status": False }), content_type="application/json") username = json_obj['userName'] first_name = json_obj['firstName'] last_name = json_obj['lastName'] password = json_obj['password'] password1 = json_obj['confirmPassword'] if password != password1: print "Passwords Are not Matching" return HttpResponse(json.dumps({ "validation": "Passwords are not Matched", "status": False }), content_type="application/json") email = validateEmail(json_obj['email']) if email != True: print "Email is already Exist." return HttpResponse(json.dumps({ "validation": "Email is already exist.Try with another Email.", "status": False }), content_type="application/json") else: email = json_obj['email'] if json_obj['addressLine1'] is None: return HttpResponse(json.dumps({ "validation": "Please Enter Your Address...!", "status": False }), content_type="application/json") else: address_line1 = json_obj['addressLine1'] address_line2 = json_obj['addressLine2'] contact_no = json_obj['mobileNo0'] contact_no = int(contact_no) contact_no = validate_mobile(str(contact_no)) if contact_no == False: return HttpResponse(json.dumps([{ "validation": "This mobile number is already used..please try with another one.", "status": False }]), content_type="application/json") else: contact_no1 = json_obj['mobileNo1'] city = json_obj['city'] state = json_obj['state'] country = json_obj['country'] pin_code = json_obj['pincode'] accounttype_obj = AccountType(optionType=1) accounttype_obj.save() group_obj_for_bank_acc = Group(optionType=0) group_obj_for_bank_acc.save() group_obj_for_cash_acc = Group(optionType=4) group_obj_for_cash_acc.save() bank_account_name = "My Bank Account" cash_account_name = "My Cash Account" bank_account_obj = Account(account_name=bank_account_name, first_name=first_name, last_name=last_name, contact_no=contact_no, address_line1=address_line1, city=city, state=state, country=country, pin_code=pin_code, accounttype=accounttype_obj, group=group_obj_for_bank_acc) bank_account_obj.save() cash_account_obj = Account(account_name=cash_account_name, first_name=first_name, last_name=last_name, contact_no=contact_no, address_line1=address_line1, city=city, state=state, country=country, pin_code=pin_code, accounttype=accounttype_obj, group=group_obj_for_cash_acc) cash_account_obj.save() user_obj = User(first_name=first_name, last_name=last_name, username=username, email=email, password=password) user_obj.set_password(password) user_obj.save() userdetail_obj = UserDetail(user=user_obj, address_line1=address_line1, address_line2=address_line2, contact_no=contact_no, city=city, state=state, country=country, pin_code=pin_code, contact_no1=contact_no1, bank_account=bank_account_obj, cash_account=cash_account_obj) userdetail_obj.save() print "Registration Successful" return HttpResponse(json.dumps({ "validation": "Registration Successful.", "redirecturl": "#/login", "status": True }), content_type="application/json")