Esempio n. 1
0
    def register(self, request):
        username = self.request.POST.get("username", "")
        password1 = self.request.POST.get("password1", "")
        password2 = self.request.POST.get("password2", "")
        email = self.request.POST.get("email", "")

        form = VmaigUserCreationForm(request.POST)

        errors = []
        # 验证表单是否正确
        if form.is_valid():
            current_site = get_current_site(request)
            site_name = current_site.name
            domain = current_site.domain
            title = u"欢迎来到 {} !".format(site_name)
            message = "".join([
                u"你好! {} ,感谢注册 {} !\n\n".format(username, site_name),
                u"请牢记以下信息:\n",
                u"用户名:{}\n".format(username),
                u"邮箱:{}\n".format(email),
                u"网站:http://{}\n\n".format(domain),
            ])
            from_email = None
            #暂时取消注册发邮件
            # try:
            #     send_mail(title, message, from_email, [email])
            # except Exception as e:
            #     logger.error("OK1")
            #     logger.error(e)
            #     logger.error(
            #         u'[UserControl]用户注册邮件发送失败:[{}]/[{}]'.format(
            #             username, email
            #         )
            #     )
            #     return HttpResponse(u"发送邮件错误!\n注册失败", status=500)

            new_user = form.save()
            user = auth.authenticate(username=username, password=password2)
            auth.login(request, user)

        else:
            # 如果表单不正确,保存错误到errors列表中
            for k, v in form.errors.items():
                # v.as_text() 详见django.forms.util.ErrorList 中
                errors.append(v.as_text())

        mydict = {"errors": errors}
        return HttpResponse(
            json.dumps(mydict),
            content_type="application/json"
        )
Esempio n. 2
0
    def register(self, request):
        username = self.request.POST.get("username", "")
        password1 = self.request.POST.get("password1", "")
        password2 = self.request.POST.get("password2", "")
        email = self.request.POST.get("email", "")

        form = VmaigUserCreationForm(request.POST)

        errors = []
        # 验证表单是否正确
        if form.is_valid():
            current_site = get_current_site(request)
            site_name = current_site.name
            domain = current_site.domain
            title = u"欢迎来到 {} !".format(site_name)
            message = "".join([
                u"你好! {} ,感谢注册 {} !\n\n".format(username, site_name),
                u"请牢记以下信息:\n",
                u"用户名:{}\n".format(username),
                u"邮箱:{}\n".format(email),
                u"网站:http://{}\n\n".format(domain),
            ])
            from_email = None
            try:
                send_mail(title, message, from_email, [email])
            except Exception as e:
                print(e.__repr__())
                logger.error(
                    u'[UserControl]用户注册邮件发送失败:[{}]/[{}]'.format(
                        username, email
                    )
                )
                return HttpResponse(u"发送邮件错误!\n注册失败", status=500)

            new_user = form.save()
            user = auth.authenticate(username=username, password=password2)
            auth.login(request, user)

        else:
            # 如果表单不正确,保存错误到errors列表中
            for k, v in form.errors.items():
                # v.as_text() 详见django.forms.util.ErrorList 中
                errors.append(v.as_text())

        mydict = {"errors": errors}
        return HttpResponse(
            json.dumps(mydict),
            content_type="application/json"
        )
Esempio n. 3
0
    def register(self,request):
        username = self.request.POST.get("username","")
        password1 = self.request.POST.get("password1","")
        password2 = self.request.POST.get("password2","")
        email = self.request.POST.get("email","")

        form = VmaigUserCreationForm(request.POST)
            
        errors = []
        #验证表单是否正确
        if form.is_valid():
            current_site = get_current_site(request)
            site_name = current_site.name
            domain = current_site.domain
            title = u"欢迎来到 %s !" % site_name
            message = u"你好! %s ,感谢注册 %s !\n\n" % (username,site_name) + \
                      u"请牢记以下信息:\n" + \
                      u"用户名:%s" % username+"\n" + \
                      u"邮箱:%s" % email+"\n" + \
                      u"网站:http://%s" % domain+"\n\n"
            from_email = None
            # try:
            #     send_mail(title, message, from_email, [email])
            # except Exception as e:
            #     logger.error(u'[UserControl]用户注册邮件发送失败:[%s]/[%s]' % (username,email))
            #     return HttpResponse(u"发送邮件错误!\n注册失败",status=500)

            new_user = form.save()
            #操作日志
            oprlog = OprLog.objects.create(
                name = 'VmaigUser',
                customer = username,
                opr_type = '创建',
                bak = '新建用户'
            )
            user = auth.authenticate(username=username, password=password2)
            auth.login(request,user)
 

        else:
            #如果表单不正确,保存错误到errors列表中
            for k,v in  form.errors.items():
                #v.as_text() 详见django.forms.util.ErrorList 中
                errors.append(v.as_text())

            
        mydict = {"errors":errors}
        return HttpResponse(json.dumps(mydict),content_type="application/json")
Esempio n. 4
0
    def register(self, request):
        username = self.request.POST.get("username", "")
        password1 = self.request.POST.get("password1", "")
        password2 = self.request.POST.get("password2", "")
        email = self.request.POST.get("email", "")

        form = VmaigUserCreationForm(request.POST)

        errors = []
        #验证表单是否正确
        if form.is_valid():
            current_site = get_current_site(request)
            site_name = current_site.name
            domain = current_site.domain
            title = u"欢迎来到 %s !" % site_name
            message = u"你好! %s ,感谢注册 %s !\n\n" % (username,site_name) + \
                      u"请牢记以下信息:\n" + \
                      u"用户名:%s" % username+"\n" + \
                      u"邮箱:%s" % email+"\n" + \
                      u"网站:http://%s" % domain+"\n\n"
            from_email = None
            # try:
            #     send_mail(title, message, from_email, [email])
            # except Exception as e:
            #     logger.error(u'[UserControl]用户注册邮件发送失败:[%s]/[%s]' % (username,email))
            #     return HttpResponse(u"发送邮件错误!\n注册失败",status=500)

            new_user = form.save()
            #操作日志
            oprlog = OprLog.objects.create(name='VmaigUser',
                                           customer=username,
                                           opr_type='创建',
                                           bak='新建用户')
            user = auth.authenticate(username=username, password=password2)
            auth.login(request, user)

        else:
            #如果表单不正确,保存错误到errors列表中
            for k, v in form.errors.items():
                #v.as_text() 详见django.forms.util.ErrorList 中
                errors.append(v.as_text())

        mydict = {"errors": errors}
        return HttpResponse(json.dumps(mydict),
                            content_type="application/json")