Beispiel #1
0
    def dispatch(self, request, *args, **kwargs):
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data['username']
                first_name = form.cleaned_data['first_name']
                last_name = form.cleaned_data['last_name']
                email = form.cleaned_data['email']
                password = form.cleaned_data['password']
                if User.objects.filter(email=email).exists():
                    return self.json_error(
                        'User with such email already exists',
                        "duplicate_email")
                try:
                    User.objects.create_user(username,
                                             email,
                                             password,
                                             first_name=first_name,
                                             last_name=last_name)
                    user = User.objects.get(email=email)
                    serializer = UserSerializer(user)
                    return self.json_success(serializer.data)

                except IntegrityError:
                    return self.json_error(
                        'User with such username already exists',
                        "duplicate_username")
            else:
                return self.json_error("Form filled incorrectly", "form_error")
        else:
            return self.json_error('Auth failed', "only_post_allowed")
Beispiel #2
0
def Register(request):#注册
    context = {}

    if request.method == 'POST':
        reg_form = RegisterForm(request.POST)
        if reg_form.is_valid():
            username = reg_form.cleaned_data['username']
            email = reg_form.cleaned_data['email']
            password = reg_form.cleaned_data['password']
            # 创建用户
            user = User.objects.create_user(username, email, password)
            user.save()
            # 登录用户
            user = auth.authenticate(username=username, password=password)
            auth.login(request, user)

            today = timezone.now().date()
            dates = []
            expends_sum = []
            incomes_sum = []

            context['username'] = username
            contents_expend = Expend.objects.filter(username_id=username)
            contents_income = Income.objects.filter(username_id=username)

            for i in range(6, -1, -1):
                date = today - timedelta(days=i)
                tomorrow = date + timedelta(days=1)
                dates.append(date.strftime('%y/%m/%d'))

                expend_detail = Expend.objects.filter(username_id=username,
                                                      date__lt=tomorrow, date__gte=date)
                expend_result = expend_detail.aggregate(expend_money_num=Sum('money'))

                income_detail = Income.objects.filter(username_id=username,
                                                      date__lt=tomorrow, date__gte=date)
                income_result = income_detail.aggregate(income_money_num=Sum('money'))

                expends_sum.append(expend_result['expend_money_num'] or 0)
                incomes_sum.append(income_result['income_money_num'] or 0)

            context['contents_expend'] = contents_expend
            context['contents_income'] = contents_income
            context['contents_user'] = user
            context['dates'] = dates
            context['expends_sum'] = expends_sum
            context['incomes_sum'] = incomes_sum

            #return redirect(request.GET.get('from', reverse('login')))
            return render(request, 'personalcenter.html', context)
    else:
        reg_form = RegisterForm()

    context = {}
    context['reg_form'] = reg_form
    return render(request, 'register.html', context)
Beispiel #3
0
    def dispatch(self, request, *args, **kwargs):
        form = RegisterForm()
        if request.method == 'POST':
            form = RegisterForm(request.POST)
            if form.is_valid():
                self.create_new_user(form)
                messages.success(request, u"You're succesfully registered!")
                return redirect(reverse("login"))

        context = {'form': form}
        return render(request, self.template_name, context)
Beispiel #4
0
def register_page(request):
    form = RegisterForm(request.POST or None)
    context = {'form': form}
    if form.is_valid():
        print(form.cleaned_data)
        username = form.cleaned_data.get('username')
        email = form.cleaned_data.get('email')
        password = form.cleaned_data.get('password')
        new_user = User.objects.create_user(username, email, password)
        print(new_user)

    return render(request, 'auth/register_page.html', context)
Beispiel #5
0
def register(request):
    """注册"""
    if request.method == "POST":
        register_form = RegisterForm(request.POST)
        if register_form.is_valid(): #执行is_valid()会执行在form.py的 clean等系列的函数
            username = register_form.cleaned_data['username']
            email = register_form.cleaned_data['email']
            password = register_form.cleaned_data['password']
            user = User.objects.create_user(username,email,password)#创建注册用户并设置密码
            user.save()
            # Redirect to a success page.
            user = auth.authenticate(username=username, password=password)
            auth.login(request,user)
            return redirect(request.GET.get("from",reverse('home')))
    else:
        register_form = RegisterForm()
    context = {}
    context['register_form'] = register_form
    return render(request, 'account/register.html', context)
def register(request):
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            user = form.save()
            username = form.cleaned_data.get('username')
            login(request, user)

            subject = 'Welcome to VerywellHealth.com World'
            message = 'Hi {}, thank you for registering in VerywellHealth. Your can now explore our website and find your body fitness routine.\n\n http://verywellhealth.herokuapp.com'.format(
                username)
            email_from = settings.EMAIL_HOST_USER
            recipient_list = [user.email, ]
            send_mail(subject, message, email_from, recipient_list, fail_silently=False)

            return redirect("index")
        else:
            for msg in form.error_messages:
                print(form.error_messages[msg])
            return render(request=request, template_name="registration/register.html", context={"form": form})

    form = RegisterForm
    return render(request=request, template_name="registration/register.html", context={"form": form})
Beispiel #7
0
def Register(request):#注册
    context = {}

    if request.method == 'POST':
        reg_form = RegisterForm(request.POST)
        if reg_form.is_valid():
            username = reg_form.cleaned_data['username']
            email = reg_form.cleaned_data['email']
            password = reg_form.cleaned_data['password']
            # 创建用户
            user = User.objects.create_user(username, email, password)
            user.save()
            #创建成员(自己)
            member_relation = '自己'
            member_description = ''
            Member.objects.create(username_id=username, member_name=username, member_relation=member_relation,
                                  description=member_description)

            # 登录用户
            user = auth.authenticate(username=username, password=password)
            auth.login(request, user)

            today = timezone.now().date()
            dates = []
            expends_sum = []
            incomes_sum = []
            results_sum = []

            sum_of_expend_this_weekend = 0  # 本周支出
            sum_of_income_this_weekend = 0  # 本周收入
            sum_of_debt_this_weekend = 0  # 本周债务

            context['username'] = username
            contents_expend = Expend.objects.filter(username_id=username)
            contents_income = Income.objects.filter(username_id=username)

            for i in range(6, -1, -1):
                date = today - timedelta(days=i)
                tomorrow = date + timedelta(days=1)
                dates.append(date.strftime('%y/%m/%d'))

                expend_detail = Expend.objects.filter(username_id=username,
                                                      date__lt=tomorrow, date__gte=date)
                expend_result = expend_detail.aggregate(expend_money_num=Sum('money'))

                income_detail = Income.objects.filter(username_id=username,
                                                      date__lt=tomorrow, date__gte=date)
                income_result = income_detail.aggregate(income_money_num=Sum('money'))

                if income_result['income_money_num'] is not None and \
                        expend_result['expend_money_num'] is not None: \
                        result = income_result['income_money_num'] - expend_result['expend_money_num']

                elif income_result['income_money_num'] is not None and \
                        expend_result['expend_money_num'] is None: \
                        result = income_result['income_money_num']

                elif income_result['income_money_num'] is None and \
                        expend_result['expend_money_num'] is not None: \
                        result = -expend_result['expend_money_num']
                else:
                    result = 0

                expends_sum.append(expend_result['expend_money_num'] or 0)
                incomes_sum.append(income_result['income_money_num'] or 0)
                results_sum.append(result)


            flag = datetime.now().weekday()
            while (flag >= 0):  # 本周总支出、总收入、总债务
                for i in range(flag + 1):
                    sum_of_expend_this_weekend += expends_sum[6 - i]
                    sum_of_income_this_weekend += incomes_sum[6 - i]
                    sum_of_debt_this_weekend += results_sum[6 - i]
                    flag = flag - 1

            context['contents_expend'] = contents_expend
            context['contents_income'] = contents_income
            context['contents_user'] = user
            context['dates'] = dates
            context['expends_sum'] = expends_sum
            context['incomes_sum'] = incomes_sum
            context['result'] = results_sum

            context['sum_of_expend_this_weekend'] = sum_of_expend_this_weekend
            context['sum_of_income_this_weekend'] = sum_of_income_this_weekend
            context['sum_of_debt_this_weekend'] = sum_of_debt_this_weekend

            #return redirect(request.GET.get('from', reverse('login')))
            return render(request, 'personalcenter.html', context)
    else:
        reg_form = RegisterForm()

    context = {}
    context['reg_form'] = reg_form
    return render(request, 'register.html', context)