예제 #1
0
 def create(self, request, *args, **kwargs):
     crypto_obj = get_data(request)
     plain_text = crypto_obj.decrypt_text(request.data['data']).replace(
         '\'', '\"')
     data = json.loads(plain_text)
     data = data if isinstance(data, dict) else {}
     try:
         serializer = self.get_serializer(data=data)
         serializer.is_valid(raise_exception=True)
         data = serializer.validated_data
         password = data.pop('password')
         user = Account(**data)
         user.set_password(password)
         user.save()
         response = crypto_obj.encrypt_text("{}".format(
             {"response": "user created."}))
         return Response({'response': response}, status.HTTP_201_CREATED)
     except IntegrityError as e:
         response = crypto_obj.encrypt_text("{}".format(
             {"response": "This username exist."}))
         return Response({"response": response},
                         status.HTTP_400_BAD_REQUEST)
     except Exception as e:
         response = crypto_obj.encrypt_text("{}".format({'response': e}))
         return Response({'response': response},
                         status=status.HTTP_400_BAD_REQUEST)
예제 #2
0
def seed_db():
    from core.models import Account,Server,ConnectionType
    local_c = ConnectionType(name='local',connection_class='local')
    local_c.save()
    local = Server(ip_address='127.0.0.1',name='localhost',connection_type_id=local_c.id)    
    local.save()
    act = Account(username='******',password='******',base_dir='/',server_id=local.id)
    act.save()
예제 #3
0
 def save(self):
     account = Account(wealth=self.wealth,
                       type=self.cleaned_data['type'],
                       name=self.cleaned_data['name'],
                       balance=self.cleaned_data['opening_balance'],
                       modified_date=datetime.utcnow(),
                       currency=self.cleaned_data['currency'],
                       opening_balance=self.cleaned_data['opening_balance'],
                       opened_date=self.cleaned_data['opened_date'])
     account.save()
     return account
예제 #4
0
 def save(self):
   account = Account(
       wealth=self.wealth,
       type=self.cleaned_data['type'],
       name=self.cleaned_data['name'],
       balance=self.cleaned_data['opening_balance'],
       modified_date=datetime.utcnow(),
       currency=self.cleaned_data['currency'],
       opening_balance=self.cleaned_data['opening_balance'],
       opened_date=self.cleaned_data['opened_date'])
   account.save()
   return account
예제 #5
0
파일: manage.py 프로젝트: nuaays/flask-ide
def seed_db():
    from core.models import Account, Server, ConnectionType
    local_c = ConnectionType(name='local', connection_class='local')
    local_c.save()
    local = Server(ip_address='127.0.0.1',
                   name='localhost',
                   connection_type_id=local_c.id)
    local.save()
    act = Account(username='******',
                  password='******',
                  base_dir='/',
                  server_id=local.id)
    act.save()
예제 #6
0
파일: views.py 프로젝트: shane-Git/EzMeal
def UserRegHandler(request):
    NewAccount = Account()
    NewAccount.username = request.POST['username'].encode('utf-8')
    NewAccount.password = request.POST['password'].encode('utf-8')
    NewAccount.urtype = request.POST['urtype'].encode('utf-8')
    NewAccount.created = datetime.now()
    NewUser = User()
    NewUser.name = request.POST['name'].encode('utf-8')
    NewUser.mobile = request.POST['mobile'].encode('utf-8')
#    NewUser.address = request.POST['address'].encode('utf-8')
    NewUser.save()
    NewAccount.urid = NewUser.id
    NewAccount.save()
    return HttpResponse(NewAccount.id) 
예제 #7
0
def signup_page(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(reverse('index_page'))

    if request.method == "POST":
        email = request.POST.get('email')
        password = request.POST.get('password')

        if Account.objects.filter(email=email).exists():
            context = {"form_message": {"title": "<span class=\"icon-caution\"></span> SIGNUP ERROR", "message": "Email already exists.", "type": "danger", "animation": "animated shake" }}
            return render(request, 'signup.html', context)

        if not email or not password:
            context = {"form_message": {"title": "<span class=\"icon-caution\"></span> SIGNUP ERROR", "message": "All fields are required.", "type": "danger", "animation": "animated shake" }}
            return render(request, 'signup.html', context)

        try:
            validate_email(email)

        except ValidationError:
            context = {"form_message": {"title": "<span class=\"icon-caution\"></span> SIGNUP ERROR", "message": "Enter a valid email address.", "type": "danger", "animation": "animated shake" }}
            return render(request, 'signup.html', context)
            
        try:
            user = Account()
            user.email = email
            user.set_password(password)
            user.is_activated = False
            user.save()
            Notification.objects.create(account=user, description="Account created.")
            token = ActivationToken(email=email)
            token.save()
            send_activation_token(request, token)
            Notification.objects.create(account=user, description="Activation mail sent.")

        except Exception as e:
            context = {"form_message": {"title": "<span class=\"icon-caution\"></span> SIGNUP ERROR", "message": "Cannot create account. Contact support team.<br/> DEBUG" + str(e), "type": "danger"}
                    }
            return render(request, 'signup.html', context)

        context = {"form_message": {"title": "<span class=\"icon-happy\"></span> SIGNUP SUCCESS", "message": " Activation mail sent.", "type": "success"}}
        return render(request, 'login.html', context)
            

    else:
        return render(request, 'signup.html')
예제 #8
0
파일: views.py 프로젝트: kcole16/finishedyo
def handle_yoauth(request):
	yoauth_token = request.GET['yoauth_token']
	url = 'http://yoauth.herokuapp.com/validate'
	payload = {'yoauth_token':yoauth_token}
	r = requests.get(url, params=payload)
	text = json.loads(r.text)
	username = str(text['user']['yo_username'])

	try:
		user = Account.objects.get(yo_name=username)
	except ObjectDoesNotExist:
		user = Account(yo_name=username, password='******')
		user.save()

	user.backend = 'django.contrib.auth.backends.ModelBackend'
	login(request, user)
	url = reverse('home')
	return HttpResponseRedirect(url)
예제 #9
0
    def form_valid(self, form):

        # save client
        form.save()
        # generate data
        num_card = utils.generateNumCard()
        num_pin = utils.generateNumPin()
        getClient = form.cleaned_data['document_number']
        # add user
        user = User(username=num_card, client=Client.objects.get(document_number=getClient))
        user.set_password(num_pin)
        user.save()
        # add card
        card = CreditCard(num_card=num_card, num_pin=num_pin,
                            expiration_date=utils.generateExpDate(), num_cvv=utils.generateNumCvv())
        card.save()
        # add account
        account = Account(
            num_account=utils.generateNumAccount(), client=Client.objects.get(document_number=getClient), card=CreditCard.objects.get(num_card=num_card))
        account.save()
        return super(SignUpView, self).form_valid(form)
예제 #10
0
        if payment_time < time.time():
             payment_time = datetime.datetime.utcfromtimestamp(payment_time).replace(tzinfo=pytz.utc)
             payment = Payment(account=account, amount=invoice.amount, date=payment_time)
             payment.save()

delete_all(Invoice)
delete_all(Charge)
delete_all(Payment)
delete_all(Account)
delete_all(UsableObject)

for site in Site.objects.all():
    # only create accounts for sites where some slices exist
    if len(site.slices.all()) > 0:
        account = Account(site=site)
        account.save()

for slice in Slice.objects.all():
    site = slice.site
    account = site.accounts.all()[0]
    serviceClass =slice.serviceClass

    if not (slice.name in ["DnsRedir", "DnsDemux", "HyperCache"]):
        continue

    now = int(time.time())/HOUR_SECONDS*HOUR_SECONDS

    charge_kind=None
    for resource in slice.serviceClass.resources.all():
        if resource.name == "cpu.cores":
            charge_kind = "reservation"
예제 #11
0
from core.models import Account, IncomeCategory, ExpenseCategory

import json

with open('data.json', 'r') as file:
    data = json.load(file)

for acc in data['account']:
    account = Account(name=acc['name'])
    account.save()

for in_c in data['incomeCategory']:
    incomeCategory = IncomeCategory(name=in_c['name'])
    incomeCategory.save()

for ex_c in data['expenseCategory']:
    expenseCategory = ExpenseCategory(name=ex_c['name'])
    expenseCategory.save()