コード例 #1
0
ファイル: views.py プロジェクト: KimballCai/foodlog
def register(request):
    # username = models.CharField(max_length=16, verbose_name='用户名')
    # password = models.CharField(max_length=16, verbose_name='密码')
    # nickname = models.CharField(max_length=16,verbose_name='昵称')
    # email = models.EmailField(max_length=16, verbose_name='邮箱')
    # img = models.ImageField(verbose_name='头像',upload_to='static/img/user/',default='static/img/user/1.jpg')
    # ctime = models.DateTimeField(auto_created=True,verbose_name='创建时间')

    if request.method == 'GET':
        obj = forms.RegisterForm()
        return render(request, 'page-register.html', {'form': obj})

    elif request.method == 'POST':
        obj = forms.RegisterForm(request.POST)
        print(obj)
        if obj.is_valid():
            data = obj.cleaned_data
            new_user = models.user_info(
                username=data.get('username'),
                password=data.get('pwd'),
                # email=data.get('email')
            )
            new_user.save()
            request.session['is_login'] = True
            request.session['user'] = data.get('username')
            return redirect('/index')
        else:
            errors = obj.errors
            return render(request, 'page-register.html', {'form': obj})
コード例 #2
0
ファイル: views.py プロジェクト: yananda93/registration
def signup(request):
    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse('root'))
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        form = forms.RegisterForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            name = form.cleaned_data['name']

            if models.User.objects.filter(email=email).first() is not None:
                messages.error(request,
                               'An account with this email already exists')
            else:
                user = models.User.objects.create_user(email=email,
                                                       password=password,
                                                       name=name)
                user = auth.authenticate(email=email, password=password)
                auth.login(request, user)
                return HttpResponseRedirect(reverse('root'))
    else:
        form = forms.RegisterForm()

    return render(request, 'signup.html', {'form': form})
コード例 #3
0
ファイル: views.py プロジェクト: hackupc/myhackupc
def signup(request, u_type):
    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse('root'))
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        form = forms.RegisterForm(request.POST, type=u_type)
        if form.is_valid() and request.recaptcha_is_valid:
            email = form.cleaned_data['email']
            password = form.cleaned_data['password']
            name = form.cleaned_data['name']

            if models.User.objects.filter(email=email).first() is not None:
                form.add_error(None,
                               'An account with this email already exists')
            else:
                models.User.objects.create_user(email=email,
                                                password=password,
                                                name=name,
                                                u_type=u_type)
                user = auth.authenticate(email=email, password=password)
                auth.login(request, user)
                next_url = request.GET.get('next', reverse('root'))
                return HttpResponseRedirect(next_url)
        if not request.recaptcha_is_valid:
            form.add_error(None, 'Invalid reCAPTCHA. Please try again.')
    else:
        form = forms.RegisterForm()

    return render(request, 'signup.html', {'form': form})
コード例 #4
0
ファイル: views.py プロジェクト: heqiang/SearchEngine
def register(request):
    if request.session.get('is_login', None):
        return redirect('/index/')
    if request.method == 'POST':
        input_code = request.POST.get('check_code').upper()
        register_form = forms.RegisterForm(request.POST)
        message = "请检查填写的内容!"
        if register_form.is_valid():
            username = register_form.cleaned_data.get('username')
            password1 = register_form.cleaned_data.get('password1')
            password2 = register_form.cleaned_data.get('password2')
            email = register_form.cleaned_data.get('email')
            sex = register_form.cleaned_data.get('sex')
            if password1 != password2:
                message = '两次输入的密码不同!'
                return render(request, 'login/register.html', locals())
            else:
                same_name_user = models.User.objects.filter(username=username)
                if same_name_user:
                    message = '用户名已经存在'
                    return render(request, 'login/register.html', locals())
                same_email_user = models.User.objects.filter(email=email)
                if same_email_user:
                    message = '该邮箱已经被注册了!'
                    return render(request, 'login/register.html', locals())
                if request.session['CheckCode'].upper()==input_code:
                        new_user = models.User()
                        new_user.username = username
                        new_user.password = hashlib.sha1(password1.encode('utf-8')).hexdigest()
                        new_user.email = email
                        new_user.sex = sex
                        new_user.save()
                        message="注册成功"
                        return redirect('/login/',locals())
                else:
                    message='验证码输入错误'
                    return render(request, 'login/register.html', locals())

        else:
            return render(request, 'login/register.html', locals())
    register_form = forms.RegisterForm()
    return render(request, 'login/register.html', locals())
コード例 #5
0
ファイル: views.py プロジェクト: breeze1355/sealion
def register(request):
    """
    用户注册
    :param request:POST
    :return: 注册成功返回登陆页面 注册失败返回提示信息
    """
    if request.method == 'POST':
        register_form = forms.RegisterForm(request.POST)
        register_error = "请检查填写的内容!"
        if register_form.is_valid():
            nick_name = register_form.cleaned_data['nick_name']
            password = register_form.cleaned_data['password']
            tel = register_form.cleaned_data['tel']
            email = register_form.cleaned_data['email']
            username = register_form.cleaned_data['username']
            std_num = register_form.cleaned_data['std_num']
            std_class = register_form.cleaned_data['std_class']
            same_tel = UserModel.objects.filter(tel=tel)
            nick_name_only = UserModel.objects.filter(nick_name=nick_name)
            if same_tel:
                register_error = '该手机号已被注册,请使用别的手机号码!'
                return render(request, 'login/register.html', locals())
            if nick_name_only:
                register_error = '此昵称已存在!'
                return render(request, 'login/register.html', locals())
            new_user = UserModel()
            new_user.nick_name = nick_name
            new_user.username = username
            new_user.password = hash_code(password)
            new_user.tel = hash_code(tel)
            new_user.email = email
            new_user.std_num = std_num
            new_user.std_class = std_class
            new_user.save()
            avatar = UserAvatar(user=new_user)
            avatar.save()
            return redirect("userApp:login")
        else:
            return render(request, 'login/register.html', locals())
    register_form = forms.RegisterForm()
    return render(request, 'login/register.html', locals())
コード例 #6
0
ファイル: views.py プロジェクト: ArifTarp/djangoBlogApp
def Register(request):
    """if request.method=="POST":
        form = forms.RegisterForm(request.POST) # Doldurulmuş formu aldık
        if form.is_valid():     # forms classındaki clean metodu sadece ve sadece burada çağrılıyor...
            # clean metodu sıkıntı olmassa değer return ediyor
            username = form.cleaned_data.get("username") # clean metodunda return ettiğimiz values sözlük yapısındaki anahtar isimlerini alıyoruz
            password = form.cleaned_data.get("password")
            
            newUser = User(username=username)
            newUser.set_password(password)
            newUser.save()

            login(request,newUser)

            return redirect("index") # djangoBlog uygulamasında urls.py'deki name tagı ile eşleşen urle gitcek
        else:
            # clean methodundan raise ile hata atarsa boş form olarak tekrar göstercez sayfayı
            context = {"form":form}
            return render(request,"register.html",context)

    else:
        form = forms.RegisterForm()
        context = {"form":form} # Sözlük olarak göndermek gerektiği için
        return render(request,"register.html",context)"""

    # 2.YÖNTEM
    form = forms.RegisterForm(
        request.POST or None
    )  # Parametre; GET request ise None, POST request ise request.POST olarak kalacak

    if form.is_valid():  # POST request olursa çalışacak burası
        username = form.cleaned_data.get("username")
        password = form.cleaned_data.get("password")

        newUser = User(username=username)
        newUser.set_password(password)
        newUser.save()

        login(request, newUser)

        messages.success(request, "Başarıyla Kayıt Oldunuz...")

        return redirect("index")

    # Hem GET, Hemde POST Olup Clean Metodu Hata Fırlatırsa Bura Çalışacak
    context = {"form": form}
    return render(request, "register.html", context)
コード例 #7
0
def register(request):
    # 2. VE KOLAY OLAN YOL :)
    form = forms.RegisterForm(
        request.POST or None)  # eğer request methodu POST ise formu posttaki bilgiler ile doldur ama eğer değilse boş kalsın
    if form.is_valid():
        username = form.cleaned_data.get("username")
        password = form.cleaned_data.get("password")
        newUser = User(username=username)
        newUser.set_password(password)
        newUser.save()
        login(request, newUser)
        messages.success(request, "Başarıyla kayıt oldunuz")  # eğer başarıyla kayıt olursa request'e mesaj yolluyoruz.
        return redirect("index")
    else:
        context = {
            'form': form
        }
        return render(request, "user/register.html", context)
    """
コード例 #8
0
 def post(self, request):
     json_str = request.body
     if not json_str:
         return to_json_data(errno=Code.PARAMERR,
                             errmsg=[error_map[Code.PARAMERR]])
     data_dict = json.loads(json_str.decode('utf8'))
     form = forms.RegisterForm(data=data_dict)
     if form.is_valid():
         username = form.cleaned_data.get('username')
         password = form.cleaned_data.get('password')
         mobile = form.cleaned_data.get('mobile')
         user = Users.objects.create_user(username=username,
                                          password=password,
                                          mobile=mobile)
         login(request, user)
         return to_json_data(errmsg='恭喜您注册成功')
     else:
         err_msg_list = []
         for item in form.errors.get_json_data().values():
             err_msg_list.append(item[0].get('message'))
         err_msg_str = '/'.join(err_msg_list)  # 拼接错误信息为一个字符串
         return to_json_data(errno=Code.PARAMERR, errmsg=err_msg_str)
コード例 #9
0
 def get(self, request):
     reg_form = forms.RegisterForm()
     return render(request, 'user/reg.html', locals())
コード例 #10
0
ファイル: views.py プロジェクト: kthackse/website
def signup(request):
    if SIGNUP_DISABLED:
        messages.error(request,
                       "The signup page has temporarily been disabled.")
        return HttpResponseRedirect(reverse("app_home"))

    current_data = dict()
    if request.user.is_authenticated:
        return HttpResponseRedirect(reverse("app_dashboard"))

    if request.method == "POST":
        form = forms.RegisterForm(request.POST)
        # TODO: Fix validation
        if form.is_valid():
            email = form.cleaned_data["email"]
            password = form.cleaned_data["password"]
            name = form.cleaned_data["name"]
            surname = form.cleaned_data["surname"]
            phone = form.cleaned_data["phone"]
            birthday = form.cleaned_data["birthday"]
            sex = form.cleaned_data["sex"]
            city = form.cleaned_data["city"]
            country = form.cleaned_data["country"]

            existing_user = User.objects.filter(email=email).first()
            if existing_user:
                if existing_user.is_active:
                    messages.add_message(
                        request,
                        messages.ERROR,
                        "Signup failed, an account with this email already exists!",
                    )
                else:
                    messages.add_message(
                        request,
                        messages.ERROR,
                        "Signup failed, a deactivated account with this email still exists, contact us for more information.",
                    )
            else:
                user = User.objects.create_participant(
                    email=email,
                    password=password,
                    name=name,
                    surname=surname,
                    phone=phone,
                    birthday=birthday,
                    sex=sex,
                    city=city,
                    country=country,
                )
                user = auth.authenticate(email=email, password=password)
                send_verify(user)
                auth.login(request, user)
                messages.success(
                    request,
                    "Thank-you for registering, remember to confirm your email!",
                )
                return HttpResponseRedirect(reverse("app_home"))
        else:
            messages.add_message(
                request,
                messages.ERROR,
                "Signup failed, some fields might be wrong or empty!",
            )
    else:
        form = forms.RegisterForm()

    current_data["form"] = form
    current_data["sexes"] = [(
        (sex.name.capitalize()
         if sex.name.lower() != "none" else "Prefer not to say"),
        sex.value,
    ) for sex in SexType]
    return render(request, "signup.html", current_data)