def cw_register(request): username = request.POST.get('username', '') password = request.POST.get('password', '') email = request.POST.get('email', '') first_name = request.POST.get('first_name', '') last_name = request.POST.get('last_name', '') zip_code = request.POST.get('zip_code', '') if User.objects.filter(email=email).exists(): return HttpResponseBadRequest(reason='An account exists for this email address.') if User.objects.filter(username=username).exists(): return HttpResponseBadRequest(reason='Sorry, this username is taken.') try: User.objects.create_user(username, email, password) user = authenticate(username=username, password=password) account = Account(user=user, email=email, first_name=first_name, last_name=last_name, zip_code=zip_code) account.save() except Exception as e: print str(e) return HttpResponseServerError(reason=str(e)) try: user.is_active = False user.save() login(request, user) print "Should be good at this point?" return HttpResponse() except Exception as e: print str(e) return HttpResponseServerError(reason=str(e))
def Deposit(): data = request.get_json() current_user_id = get_jwt_identity() FromAccount = Account.query.filter_by(userID=current_user_id, coinID=data["coinID"]).first() # Varification if Exist Account if FromAccount is None: newaccount = Account(current_user_id, data["coinID"], data["amount"]) db.session.add(newaccount) db.session.commit() FromAccount = Account.query.filter_by(userID=current_user_id, coinID=data["coinID"]).first() # Deposit FromAccount.Deposit(data["amount"]) db.session.flush() db.session.commit() newtrans = CryptoTransaction(data["date"], current_user_id, current_user_id, FromAccount.id, data["amount"]) db.session.add(newtrans) db.session.commit() return jsonify({"msg": "El Deposito se realizó satisfactoriamente"}), 200
def hk_register(request): username = request.POST.get('username', '') password = request.POST.get('password', '') email = request.POST.get('email', '') if User.objects.filter(email=email).exists(): return HttpResponseBadRequest( reason='A user exists for this email address.') if User.objects.filter(username=username).exists(): return HttpResponseBadRequest(reason='Sorry, this username is taken.') try: User.objects.create_user(username, email, password) user = authenticate(username=username, password=password) account = Account(user=user, email=email) account.save() except Exception as e: print str(e) return HttpResponseServerError(reason=str(e)) try: user.is_active = False user.save() login(request, user) return HttpResponse() except Exception as e: print str(e) return HttpResponseServerError(reason=str(e))
def cw_register(request): form = AccountRegistrationForm(request.POST or None) if request.method == 'POST': # Form Validation if form.is_valid(): username = form.clean_username() password = form.clean_password() email = form.clean_email() # Create a New Account try: User.objects.create_user(username, email, password) user = authenticate(username=username, password=password) account = Account(user=user) if not settings.CLOSED_BETA: account.beta_access = True account.save() user.is_active = True user.save() uid = urlsafe_base64_encode(force_bytes(user.pk)) token = account_activation_token.make_token(user) domain = get_current_site(request).domain base_url = "http://{domain}/auth/activate_account/{uid}/{token}/" url_with_code = base_url.format(domain=domain, uid=uid, token=token) # Send Email Verification Message # TODO: Move this to string templates email_context = { 'title': 'Verify your email with CiviWiki', 'body': ("Welcome to CiviWiki! Follow the link below to verify your email with us. " "We're happy to have you on board :)"), 'link': url_with_code } send_email.delay(subject="CiviWiki Account Setup", recipient_list=[email], context=email_context) login(request, user) return HttpResponse() except Exception as e: return HttpResponseServerError(reason=str(e)) else: response = { 'success': False, 'errors': [error[0] for error in form.errors.values()] } return JsonResponse(response, status=400) else: return HttpResponseBadRequest(reason="POST Method Required")
def setUp(self): User = get_user_model() user_1 = User.objects.create_user(email='*****@*****.**', password='******') user_2 = User.objects.create_user(email='*****@*****.**', password='******') TEST_ACCOUNTS = [] self.accounts = Account.objects.bulk_create( [Account(**account) for account in TEST_ACCOUNTS])
def Transfer(): data = request.get_json() current_user_id = get_jwt_identity() FromAccount = Account.query.filter_by(userID=current_user_id, coinID=data["coinID"]).first() if FromAccount is None: return jsonify( {"msg": "El usuario no posee una cuenta de dicha moneda"}), 400 elif FromAccount.balance < data["amount"]: return jsonify({"msg": "El usuario no posee una saldo suficiente"}), 400 else: UserFinal = CryptoUser.query.filter_by( userCode=data["UserCode"].lower(), is_Active=True).first() if UserFinal is None: return jsonify({"msg": "El destinatario no existe"}), 400 else: ToAccount = Account.query.filter_by(userID=UserFinal.id, coinID=data["coinID"]).first() if ToAccount is None: newaccount = Account(UserFinal.id, data["coinID"], data["amount"]) db.session.add(newaccount) db.session.commit() ToAccount = Account.query.filter_by( userID=UserFinal.id, coinID=data["coinID"]).first() # Retiro FromAccount.Deposit((0 - data["amount"])) db.session.flush() db.session.commit() newtrans = CryptoTransaction(data["date"], current_user_id, UserFinal.id, FromAccount.id, (0 - data["amount"])) db.session.add(newtrans) db.session.commit() # Deposito ToAccount.Deposit(data["amount"]) db.session.flush() db.session.commit() newtrans = CryptoTransaction(data["date"], current_user_id, UserFinal.id, ToAccount.id, data["amount"]) db.session.add(newtrans) db.session.commit() return jsonify( {"msg": "La transferencia se realizó satisfactoriamente"}), 200
def post(self, request): try: data = json.loads(request.body) account = Account(**data) account.save() return HttpResponse(status=201, content=json.dumps({'id': account.id}), content_type='application/json') except: rollbar.report_exc_info()
def register_submit(request): username = request.POST.get('username') password = request.POST.get('password') email = request.POST.get('email') qq = request.POST.get('qq') print '%s,%s,%s,%s', (username, password, email, qq) account = Account() account.username = username account.password = password account.mail = email account.QQ = qq save_account(account) return render_to_response('index.html', locals())
def setUpClass(cls): DBModel.metadata.drop_all(sqla_engine) DBModel.metadata.create_all(sqla_engine) r1, r2 = Role(name='admin'), Role(name='pikus') DBSession.add(r1) DBSession.add(r2) a = Account(username='******', fullName='Greg Burek', email='*****@*****.**') a.set_password('dupa') a.roles.extend((r1, r2)) DBSession.add(a) DBSession.commit() cls.DBSession = DBSession
def save(self): user = Account(email=self.validated_data['email'], first_name=self.validated_data['first_name'], last_name=self.validated_data['last_name'], username=self.validated_data['username'], address=self.validated_data['address'], city=self.validated_data['city'], zip_code=self.validated_data['zip_code'], country=self.validated_data['country']) password = self.validated_data['password'] password2 = self.validated_data['password2'] if password != password2: raise serializers.ValidationError( {'password': '******'}) user.set_password(password) user.save() Token.objects.get_or_create(user=user) return user
def CreateAccount(): data = request.get_json() if data is None: return "La solicitud en nula", 400 if 'coinID' not in data: return 'Necesita especificar coin_ID', 400 if 'amount' not in data: return 'Necesita especificar la cantidad', 400 if 'date' not in data: return 'Necesita especificar la fecha', 400 return "ok", 200 current_user_id = get_jwt_identity() existAccount = Account.query.filter_by(userID=current_user_id, coinID=data["coinID"]).first() if existAccount is None: newaccount = Account(current_user_id, data["coinID"], data["amount"]) db.session.add(newaccount) db.session.commit() FromAccount = Account.query.filter_by(userID=current_user_id, coinID=data["coinID"]).first() newtrans = CryptoTransaction(data["date"], current_user_id, current_user_id, FromAccount.id, data["amount"]) db.session.add(newtrans) db.session.commit() return jsonify(newaccount.serializebyUser()), 200 else: return jsonify({"msg": "Ya hay una cuenta creada con dicha moneda"}), 406
def beta_register(request): """ Special registration request for beta access """ # Beta Check beta_token = request.POST.get('beta_token', '') if beta_token: email = request.POST.get('email' '') try: invitation = Invitation.objects.get(invitee_email=email) except Invitation.DoesNotExist: response_data = { "message": "Beta invitation does not exist for this email", "error": "NO_BETA_INVITE" } return JsonResponse(response_data, status=400) if invitation.verification_code != beta_token: response_data = { "message": "The beta token is not valid", "error": "INVALID_BETA_TOKEN" } return JsonResponse(response_data, status=400) else: response_data = { "message": "Missing Beta Token", "error": "MISSING_BETA_TOKEN" } return JsonResponse(response_data, status=400) form = AccountRegistrationForm(request.POST or None) if request.method == 'POST': # Form Validation if form.is_valid(): username = form.clean_username() password = form.clean_password() email = form.clean_email() # Create a New Account try: User.objects.create_user(username, email, password) user = authenticate(username=username, password=password) account = Account(user=user) account.beta_access = True account.is_verfied = True account.save() invitation = Invitation.objects.get(invitee_email=email) invitation.invitee_user = user invitation.save() user.is_active = True user.save() login(request, user) return HttpResponse() except Exception as e: return HttpResponseServerError(reason=str(e)) else: response = { 'success': False, 'errors': [error[0] for error in form.errors.values()] } return JsonResponse(response, status=400) else: return HttpResponseBadRequest(reason="POST Method Required")
def test__reserve_money__insuficient_funds__should_raise_insuficient_funds_exception( self): target = Account() target.money = 100 assert_that(target.reserve_money).raises( InsuficientFundsException).when_called_with(200)
def test__execute_presentment__acount_with_100_reserved__should_execute_presentment( self): target = Account() target.money = 100 target.reserve_money(60) assert_that(target.execute_presentment(60))
def test__reserve_money__account_with_100_reserve_40__should_have_60_available( self): target = Account() target.money = 100 target.reserve_money(60) assert_that(target.get_available_money()).is_equal_to(40)
def test__reserve_money__account_has_funds__account_reserved_money_should_increase( self): target = Account() target.money = 100 target.reserve_money(50) assert_that(target.reserved_money).is_equal_to(50)
def make_account(**kwargs): user = User.objects.get(username=kwargs['username']) if 'username' in kwargs: kwargs.pop('username') acc = Account(user=user, **kwargs) acc.save()