Beispiel #1
0
def process_request(request):
    print('>>>>>>>>>>>>>>>>>>>>> THIS IS SIGNUP.PY')

    clientemail = request.POST.get('first_name')
    clientmessage = request.POST.get('last_name')
    print('>>>>>>>>>> fname was', clientemail)
    print('>>>>>>>>>> lname was', clientmessage)

    # process the form (ie validation)
    form = SignupForm()
    if request.method == 'POST':  # just submitted the form
        form = SignupForm(request.POST)
        if form.is_valid():
            print('>>>>>>>>>>>>>>>>>> THE FORM IS VALID?')
            u = User()
            u.username = form.cleaned_data.get('username')
            u.first_name = form.cleaned_data.get('first_name')
            u.last_name = form.cleaned_data.get('last_name')
            u.email = form.cleaned_data.get('email')
            u.set_password(form.cleaned_data.get('password'))
            u.address1 = form.cleaned_data.get('address')
            u.address2 = form.cleaned_data.get('address2')
            u.save()
            return HttpResponseRedirect('/homepage/index/')

    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'signup.html', template_vars)
Beispiel #2
0
def register(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']
            phone = uf.cleaned_data['phone']
            domain = uf.cleaned_data['domain']
            vip = uf.cleaned_data['vip']
            clientname = uf.cleaned_data['clientname']

            user = User()
            user.username = username
            user.password = password
            user.email = email
            user.phone = phone
            user.domain = domain
            user.vip = vip
            user.clientname = clientname
            user.save()

            return render_to_response('success.html', {'username': username})
    else:
        uf = UserForm()
    return render_to_response('register.html', {'uf': uf})
Beispiel #3
0
def register(request):
    if request.method == "POST":
        uf = UserFrom(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']
            qq = uf.cleaned_data['qq']
            userResult = User.objects.filter(username=username,
                                             password=password)
            #error=[]
            filterResult = User.objects.filter(username=username)
            if len(filterResult) > 0:
                return render_to_response('hasregister.html',
                                          {'username': username})

            else:
                user = User()
                user.username = username
                user.password = password
                user.email = email
                user.qq = qq
                user.save()
                return render_to_response('success.html',
                                          {'username': username})
    else:
        uf = UserFrom()
    return render_to_response('register.html', {'uf': uf})
Beispiel #4
0
def register2(request):
    print("hhhhhhhhh====")
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息

            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            phone = uf.cleaned_data['phone']
            email = uf.cleaned_data['email']
            #将表单写入数据库
            print('1111======')
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            user.email = email
            user.save()
            print('save======')
            #返回注册成功页面
            return render(request, 'success.html', {'username': username})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf': uf})
Beispiel #5
0
def register2(request):
    print("hhhhhhhhh====")
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
			
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            phone = uf.cleaned_data['phone']
            email = uf.cleaned_data['email']
            #将表单写入数据库
            print('1111======')
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            user.email = email
            user.save()
            print('save======')
            #返回注册成功页面
            return render(request, 'success.html', {'username':username})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf':uf})
Beispiel #6
0
def process_request(request):
    print('>>>>>>>>>>>>>>>>>>>>> THIS IS SIGNUP.PY')

    clientemail = request.POST.get('first_name')
    clientmessage = request.POST.get('last_name')
    print('>>>>>>>>>> fname was', clientemail)
    print('>>>>>>>>>> lname was', clientmessage)

    # process the form (ie validation)
    form = SignupForm()
    if request.method == 'POST': # just submitted the form
        form = SignupForm(request.POST)
        if form.is_valid():
            print('>>>>>>>>>>>>>>>>>> THE FORM IS VALID?')
            u = User()
            u.username = form.cleaned_data.get('username')
            u.first_name = form.cleaned_data.get('first_name')
            u.last_name = form.cleaned_data.get('last_name')
            u.email = form.cleaned_data.get('email')
            u.set_password(form.cleaned_data.get('password'))
            u.address1 = form.cleaned_data.get('address')
            u.address2 = form.cleaned_data.get('address2')
            u.save()
            return HttpResponseRedirect('/homepage/index/')

    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'signup.html', template_vars)
def create_users():
	User.objects.exclude(pk=1).delete()
	
	for pk, fields in users.iteritems():
		if pk != 1:
			if fields['email'] != '':
				existing = User.objects.filter(email = fields['email'])
				if existing.count() > 0:
					ou = existing[0]
					if ou.is_active == False and fields['is_active'] == True:
						replace_users[ou.pk] = pk
						for k,v in replace_users.iteritems():
							if v == ou.pk:
								replace_users[k] = pk
						ou.delete()
					elif ou.is_active == True and fields['is_active'] == False:
						replace_users[pk] = ou.pk
						for k,v in replace_users.iteritems():
							if v == pk:
								replace_users[k] = ou.pk
						continue
					else:
						replace_users[ou.pk] = pk
						for k,v in replace_users.iteritems():
							if v == ou.pk:
								replace_users[k] = pk
						ou.delete()

			#print "email:", fields['email']
			nu = User(pk=pk)
			nu.username = fields['username']
			if fields['email']:
				nu.email = fields['email']
				nu.status = 1
			nu.password = fields['password']
			nu.full_name = fields['profile']['full_name']
			nu.message = fields['profile']['message']
			nu.is_active = fields['is_active']
			nu.is_staff = fields['is_staff']
			nu.is_superuser = fields['is_superuser']
			nu.comment_count = fields['profile']['comment_count']
			nu.dateo_count = fields['profile']['item_count']
			nu.vote_count = fields['profile']['vote_count']
			nu.client_domain = datea
			nu.save()

			joined = date_parser(fields['date_joined'])
			lastlog = date_parser(fields['last_login'])
			User.objects.filter(pk=nu.pk).update(date_joined=joined, created=joined, last_login=lastlog)

	for pk, fields in usersSocial.iteritems():
		if fields['user'] != 1:
			nusoc = UserSocialAuth(pk=pk)
			nusoc.provider = fields['provider']
			nusoc.uid = fields['uid']
			nusoc.user_id = get_user(int(fields['user']))
			nusoc.extra_data = fields['extra_data']
			nusoc.save()
Beispiel #8
0
    def commit(self, req):
        u = User()
        u.email = self.cleaned_data.get('email')
        u.set_password(self.cleaned_data.get('password'))
        u.save()

        user = authenticate(username=u.email,
                            password=self.cleaned_data.get('password'))

        login(req, user)
Beispiel #9
0
def createSuperuser():
    from django.utils import timezone
    from account.models import User, Profile
    print(bcolors.OKBLUE + "\n 建立超級管理員帳號" + bcolors.ENDC)
    try:
        while(True):
            username = raw_input("帳號: ")
            check = len(list(User.objects.filter(username=username)))
            if check==0:
                break
            print(bcolors.FAIL + "帳號已經被註冊 \n" + bcolors.ENDC)
        
        password = ""
        password2 = ""
        while(True):
            password = getpass.getpass("密碼: ")
            password2 = getpass.getpass("密碼(再一次): ")
            if password==password2:
                break
            else:
                print(bcolors.FAIL + "密碼不一樣,重新輸入 \n"  + bcolors.ENDC)
                
        while(True):
            email = raw_input("電子郵件: ")
            
            if email_valid(email):
                break
            print(bcolors.FAIL + "請輸入正確的電子郵件"  + bcolors.ENDC)
        
        admin = User()
        admin.username = username
        admin.set_password(password)
        admin.email = email
        admin.is_superuser = True
        admin.is_staff = True
        admin.is_active = True
        admin.date_joined = timezone.now()
        admin.save()
        
        userProflie = Profile()
        userProflie.user = admin
        userProflie.fullName=username
        userProflie.type = 2  #0=normal user, 1=manager, 2=administrator
        userProflie.isActive = True
        userProflie.isAuth = False
        userProflie.save()
        
        print(bcolors.OKBLUE + "\n "+ username +"超級管理員帳號建立成功 \n \n" + bcolors.ENDC)
    except Exception as e:
        s = str(e)
        print(bcolors.FAIL + "\n\n取消建立帳號 \n"  + bcolors.ENDC)
        if """does not exist""" in s:
            print(bcolors.FAIL + "資料庫有問題,請檢查 \n"  + bcolors.ENDC)
Beispiel #10
0
def process_request(request):
  
  #process the form
  form = CreateUserForm()
  if request.method == 'POST':  # just submitted the form
    form = CreateUserForm(request.POST)
    if form.is_valid():
      u = User()
      u.username = form.cleaned_data.get('username')
      u.first_name = form.cleaned_data.get('first_name')
      u.last_name = form.cleaned_data.get('last_name')
      u.address1 = form.cleaned_data.get('address1')
      u.address2 = form.cleaned_data.get('address2')
      u.set_password(form.cleaned_data.get('password'))
      u.email = form.cleaned_data.get('email')
      u.birth = form.cleaned_data.get('birthdate')
      u.phone_number = form.cleaned_data.get('phone_number')
      
      perms = form.cleaned_data.get('user_permissions')
      groups = form.cleaned_data.get('groups')
      u.save()
      
      u.user_permissions.clear()
      for x in perms:
        u.user_permissions.add(x)
        print(x)
        
      u.groups.clear()
      for x in groups:
        u.groups.add(x)
        print(x)
      u.save()
      
     
      
      #u2 = UserUserGroups()
      
      #u2.user_id = u.id
      #u2.permission_id = form.cleaned_data.get('user_permissions')
      #u2.group = form.cleaned_data.get('groups')
      
      #u.save()
      #u2.save()
      # authenticate(username=form.cleaned_data.get('username'),password=form.cleaned_data.get('password'))
      # login(request, form.user)    
      # create a user object
      # fill the user object with the data from the form
      return HttpResponseRedirect('/manager/users/')
      
  template_vars = {
    'form': form,
  }
  return dmp_render_to_response(request, 'userscreate.html', template_vars)
Beispiel #11
0
def register(request):
    if request.method=='POST':
        uf=UserForm(request.POST)
        if uf.is_valid():
            username=uf.cleaned_data['username']
            password=uf.cleaned_data['password']
            emali=uf.cleaned_data['email']
            user=User()#User models
            user.username=username
            user.password=password
            user.email=emali
            user.save()
            return render(request,'success.html',{'username':username})
    else:
        uf=UserForm()
        return render(request,'register.html',{'uf':uf})
Beispiel #12
0
def create():
    try:
        while(True):
            username = raw_input("帳號: ")
            check = len(list(User.objects.filter(username=username)))
            if check==0:
                break
            print(bcolors.FAIL + "帳號已經被註冊 \n" + bcolors.ENDC)
        
        password = ""
        password2 = ""
        while(True):
            password = getpass.getpass("密碼: ")
            password2 = getpass.getpass("密碼(再一次): ")
            if password==password2:
                break
            else:
                print(bcolors.FAIL + "密碼不一樣,重新輸入 \n"  + bcolors.ENDC)
                
        while(True):
            email = raw_input("電子郵件: ")
            
            if email_valid(email):
                break
            print(bcolors.FAIL + "請輸入正確的電子郵件"  + bcolors.ENDC)
        
        admin = User()
        admin.username = username
        admin.set_password(password)
        admin.email = email
        admin.is_superuser = True
        admin.is_staff = True
        admin.is_active = True
        admin.date_joined = timezone.now()
        admin.save()
        
        userProflie = Profile()
        userProflie.username = username
        userProflie.user = admin
        userProflie.save()
        print(bcolors.OKBLUE + "\n "+ username +"帳號建立成功 \n \n" + bcolors.ENDC)
    except Exception as e:
        s = str(e)
        print(bcolors.FAIL + "\n\n取消建立帳號 \n"  + bcolors.ENDC)
        if """does not exist""" in s:
            print(bcolors.FAIL + "資料庫有問題,請檢查 \n"  + bcolors.ENDC)
Beispiel #13
0
def register(request):
    if request.method == 'POST':
        uf = UserForm(request.POST)
        if uf.is_valid():
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']

            user = User()
            user.username = username
            user.password = password
            user.email = email
            user.save()
            return render_to_response('success.html', {'username': username})
    else:
        uf = UserForm()
    return render_to_response('register.html', {'uf': uf})
Beispiel #14
0
def register(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
            username = uf.cleaned_data['username']
            passworld = uf.cleaned_data['passworld']
            email = uf.cleaned_data['email']
            #将表单写入数据库
            user = User()
            user.username = username
            user.passworld = passworld
            user.email = email
            user.save()
            #返回注册成功页面
            return render_to_response('success.html',{'username':username})
    else:
        uf = UserForm()
    return render_to_response('register.html',{'uf':uf})
Beispiel #15
0
def register(request):
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
            username = uf.cleaned_data['username']
            passworld = uf.cleaned_data['passworld']
            email = uf.cleaned_data['email']
            #将表单写入数据库
            user = User()
            user.username = username
            user.passworld = passworld
            user.email = email
            user.save()
            #返回注册成功页面
            return render_to_response('success.html',{'username':username})
    else:
        uf = UserForm()
    return render_to_response('register.html',{'uf':uf})
Beispiel #16
0
def register(request):
    """
    注册账号界面
    """
    message = ""
    if request.session.get('is_login', None):
        return redirect('/account/')

    if request.method == 'POST':
        username = request.POST.get('username')
        email = request.POST.get('email')
        password1 = request.POST.get('password1')
        password2 = request.POST.get('password2')
        message = "请检查填写的内容!"
        if _makesure_password(password1, password2):
            message = _makesure_password(password1, password2)
        else:
            same_username = User.objects.filter(username=username)
            same_email = User.objects.filter(email=email)
            if same_username:
                message = '用户名已经存在!'
            elif same_email:
                message = '该邮箱已经被注册了!'
            else:
                new_user = User()
                new_user.username = username
                new_user.email = email
                new_user.password = _hash_code(password1)
                new_user.save()
                code = _make_confirm_string(new_user)
                _send_email(email, code)
                message = '请前往邮箱进行确认!'
                return render(request, 'account/login.html',
                              {'message': message})

    captcha_form = forms.captchaForm(request.POST)
    content = {
        'captcha_form': captcha_form,
        'message': message,
        'page_register': True
    }

    return render(request, 'account/register.html', content)
Beispiel #17
0
    def clean(self):
        name = self.cleaned_data.get('username')
        username = "******" + name
        print(username)
        password = self.cleaned_data.get('password')
        print(password)
        filter = '(sAMAccountName=' + name + ')'
        s = Server('www.shopfomo.me', get_info=ALL)
        c = Connection(s,
                       user=username,
                       password=password,
                       authentication=NTLM)
        c.bind()
        c.search('dc=shopfomo, dc=local',
                 filter,
                 attributes=['mail', 'sn', 'givenName', 'sAMAccountName'])
        if len(c.entries) > 0:
            if User.objects.filter(email=(name + '@shopfomo.me')).count() > 0:
                self.user = authenticate(
                    email=(name + '@shopfomo.me'),
                    password=self.cleaned_data.get('password'))
            else:
                #make the user
                myUser = User()

                #load up the user
                myUser.first_name = c.entries[0].givenName
                myUser.last_name = c.entries[0].sn
                myUser.email = name + '@shopfomo.me'
                myUser.set_password(self.cleaned_data.get('password'))

                #save the new user
                myUser.save()
                self.user = authenticate(
                    email=(name + '@shopfomo.me'),
                    password=self.cleaned_data.get('password'))
        else:
            self.user = authenticate(
                email=self.cleaned_data.get('username'),
                password=self.cleaned_data.get('password'))
        if self.user is None:
            raise forms.ValidationError('Invalid email or password.')
        return self.cleaned_data
Beispiel #18
0
def register(request):
    if request.method == 'POST':
        uf = RegisterFrom(request.POST)
        if uf.is_valid():
            #get post information
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']
            #write data into sql
            user = User()
            user.username = username
            user.password = password
            user.email = email
            user.save()
            #return successed page
            return render_to_response('successRegister.html', {'username': username})
    else:
        uf = RegisterFrom()
    return render_to_response('register.html', {'uf': uf}, context_instance=RequestContext(request))
Beispiel #19
0
def create_account(username: str,
                   password: str,
                   register_type=account_constant.ACCOUNT_REGISTER_TYPE_EMAIL,
                   **extra_fields):
    """
        创建用户
    :param username: 用户名 str
    :param password: 密码 str
    :param register_type: 注册类型 int (默认为邮箱类型)
    :param extra_fields: 额外扩展字段
    :return: created, user
    """
    try:
        email = extra_fields.get("email", None)
        phone = extra_fields.get("phone", None)
        avatar = extra_fields.get("avatar", None)
        nickname = extra_fields.get("nickname", None)
        gender = extra_fields.get("gender")

        user = User()
        user.email = email
        user.phone = phone
        user.avatar = avatar
        user.nickname = nickname
        user.gender = gender

        user.username = username
        user.register_type = register_type
        user.set_password(password)

        # 初始化修改头像等时间为10天前,以便可以创建后直接修改头像等
        default_change_datetime = timezone.datetime.now().date(
        ) - timezone.timedelta(days=10)
        user.avatar_change_date = default_change_datetime
        user.nickname_change_date = default_change_datetime

        user.save()
        return True, user

    except Exception as e:
        logger.error(e)
        return False, None
Beispiel #20
0
def register(request):
    if request.method == 'POST':
        uf = RegisterFrom(request.POST)
        if uf.is_valid():
            #get post information
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            email = uf.cleaned_data['email']
            #write data into sql
            user = User()
            user.username = username
            user.password = password
            user.email = email
            user.save()
            #return successed page
            return render_to_response('successRegister.html',
                                      {'username': username})
    else:
        uf = RegisterFrom()
    return render_to_response('register.html', {'uf': uf},
                              context_instance=RequestContext(request))
Beispiel #21
0
def register(request):
    error = []
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            password2 = uf.cleaned_data['password2']
            phone = uf.cleaned_data['phone']
            email = uf.cleaned_data['email']
            #增加验证信息
            if not User.objects.all().filter(username=username):
                if uf.pwd_validate(password, password2):
                    #将表单写入数据库
                    print('1111======')
                    user = User()
                    user.username = username
                    user.password = password
                    user.phone = phone
                    user.email = email
                    user.save()
                    print('save======')
                    #返回注册成功页面
                    return render(request, 'home_base.html', {
                        'username': username,
                        'logined': True
                    })
                else:
                    error.append('请输入相同的密码')
            else:
                error.append('用户名已存在')

            return render(request, 'register.html', {'uf': uf, 'error': error})
        else:
            print("error===")
            return render(request, 'register.html', {'uf': uf, 'error': error})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf': uf, 'error': error})
Beispiel #22
0
    def commit(self):

        #make the user
        myUser = User()

        #load up the user
        myUser.first_name = self.cleaned_data.get('first_name')
        myUser.last_name = self.cleaned_data.get('last_name')
        myUser.email = self.cleaned_data.get('email')
        myUser.birthdate = self.cleaned_data.get('birthdate')
        myUser.address = self.cleaned_data.get('address')
        myUser.city = self.cleaned_data.get('city')
        myUser.state = self.cleaned_data.get('state')
        myUser.zipcode = self.cleaned_data.get('zipcode')
        myUser.set_password(self.cleaned_data.get('password'))

        #save the new user
        myUser.save()

        user = authenticate(email=self.cleaned_data.get('email'),
                            password=self.cleaned_data.get('password'))
        login(self.request, user)
Beispiel #23
0
def process_request(request):
    form = SignupForm()
    if request.method == 'POST':
        form=SignupForm(request.POST)
        if form.is_valid():
            u = User()
            u.username = form.cleaned_data.get('username')
            u.first_name = form.cleaned_data.get('firstName')
            u.last_name = form.cleaned_data.get('lastName')
            u.email = form.cleaned_data.get('email')
            u.address1 = form.cleaned_data.get('address1')
            u.address2 = form.cleaned_data.get('address2')
            u.set_password(form.cleaned_data.get('password'))
            u.save()
            user = authenticate(username=form.cleaned_data.get('username'), password=form.cleaned_data.get('password'))
            login(request, user)
            return HttpResponseRedirect('/homepage/index/')
    
    template_vars = {
        'form': form,
    }
    return dmp_render_to_response(request, 'signup.html', template_vars)
Beispiel #24
0
def register(request):
    error=[]
    if request.method == "POST":
        uf = UserForm(request.POST)
        if uf.is_valid():
            #获取表单信息
            username = uf.cleaned_data['username']
            password = uf.cleaned_data['password']
            password2 = uf.cleaned_data['password2']
            phone = uf.cleaned_data['phone']
            email = uf.cleaned_data['email']
            #增加验证信息
            if not User.objects.all().filter(username=username):
                if uf.pwd_validate(password, password2):
                    #将表单写入数据库
                    print('1111======')
                    user = User()
                    user.username = username
                    user.password = password
                    user.phone = phone
                    user.email = email
                    user.save()
                    print('save======')
                    #返回注册成功页面
                    return render(request, 'home_base.html', {'username':username,'logined':True})
                else:
                    error.append('请输入相同的密码')
            else:
                error.append('用户名已存在')

            return render(request, 'register.html', {'uf': uf, 'error': error})
        else:
            print("error===")
            return render(request, 'register.html', {'uf': uf, 'error': error})
    else:
        uf = UserForm()
        return render(request, 'register.html', {'uf':uf, 'error':error})
Beispiel #25
0
def create_order(request):
    args = {
        'form': OrderForm(),
        'delivery_mass': DeliveryType.objects.all(),
        'user': request.user,
        'user_active': request.user.is_authenticated(),
        'cart_sum': get_sum(request),
    }
    args.update(csrf(request))
    is_valid = True

    if request.user.is_authenticated():
        ord = Order()
        ord.first_name = request.user.first_name
        ord.last_name = request.user.last_name
        ord.email = request.user.email
        ord.phone = request.user.phone
        ord.city = request.user.city
        ord.address = request.user.address
        args['form'] = OrderForm(instance=ord)

    if request.POST:
        if request.POST.get('first_name', "") == "":
            args['user_inform_error'] = True
            args['first_name_error'] = "error_field"
            is_valid = False
        if request.POST.get('last_name', "") == "":
            args['user_inform_error'] = True
            args['last_name_error'] = "error_field"
            is_valid = False
        if request.POST.get('email', "") == "":
            args['user_inform_error'] = True
            args['email_error'] = "error_field"
            is_valid = False
        if request.POST.get('phone', "") == "":
            args['user_inform_error'] = True
            args['phone_error'] = "error_field"
            is_valid = False

        if request.POST.get('city', "") == "":
            args['address_inform_error'] = True
            args['city_error'] = "error_field"
            is_valid = False
        if request.POST.get('address', "") == "":
            args['address_inform_error'] = True
            args['address_error'] = "error_field"
            is_valid = False

        if request.POST.get('delivery', "") == "":
            args['delivery_error'] = "выберите тип доставки"
            args['delivery_error'] = "error_field"
            is_valid = False

        if 'register' in request.POST:
            try:
                email = request.POST.get('email', "")
                User.objects.get(email=email)
                args['register_error'] = "Пользователь с таким email уже разегистрирован"
                is_valid = False
            except User.DoesNotExist:
                pass

        form = OrderForm(request.POST)
        if is_valid and form.is_valid():
            order = form.save(commit=False)
            delivery = DeliveryType.objects.get(id=request.POST['delivery'])
            order.delivery = delivery.title
            order.delivery_price = delivery.price
            order.status = 0
            print(get_sum(request))
            order.sum = get_sum(request)
            if request.user.is_authenticated():
                order.user = request.user
            order.save()
            cart = get_cart(request)
            if cart:
                for pr in CartProduct.objects.filter(cart=cart):
                    if pr.product.sale_status:
                        pr.price_order = pr.product.price_sale
                    else:
                        pr.price_order = pr.product.price
                    pr.save()
                    order.products.add(pr)
            else:
                args['cart_error'] = "в вашей корзине ничего нет"
            order.save()

            if 'register' in request.POST:
                new_user = User()
                new_user.first_name = request.POST.get('first_name', "")
                new_user.last_name = request.POST.get('last_name', "")
                new_user.email = request.POST.get('email', "")
                new_user.phone = request.POST.get('phone', "")
                new_user.city = request.POST.get('city', "")
                new_user.address = request.POST.get('address', "")
                new_user.username = translit(new_user.first_name) + "_" + random_str(6)
                password = random_str(7)
                new_user.set_password(password)
                new_user.save()
                # отправка уведомления
                user = auth.authenticate(username=new_user.username, password=password)
                if user is not None and user.is_active:
                    auth.login(request, user)
                return redirect("/orders/reg_thanks/")
            elif request.user.is_authenticated():
                request.user.last_name = request.POST.get('last_name', "")
                request.user.first_name = request.POST.get('first_name', "")
                request.user.phone = request.POST.get('phone', "")
                request.user.city = request.POST.get('city', "")
                request.user.address = request.POST.get('address', "")
                request.user.save()

            return redirect("/orders/thanks/")

        args['form'] = form
    return render_to_response("create_order.html", args)
Beispiel #26
0
##
# Users
#

print('\nCreating Users...')

# This list is for choosing random users for other model associations
users = []

# Delete existing user objects
User.objects.all().delete()

# Create my superuser
u = User()
u.username = '******'
u.email = '*****@*****.**'
u.set_password('qwer1234')
u.first_name = 'Andy'
u.last_name = 'Mockler'
u.address1 = '850 N University Ave'
u.address2 = '303'
u.birth = datetime.datetime.now()
u.phone_number = '(801) 388-8448'
u.is_staff = True
u.is_superuser = True
u.save()
for group in Group.objects.all():
    u.groups.add(group)

# Create generic users
for i in range(1, 10):
Beispiel #27
0
    def post(self, request):

        parameter_missing = False
        parameter_missing_name = ""
        if request.data.get("first_name") is None or request.data.get(
                "first_name") == "":
            parameter_missing_name = parameter_missing_name + "first_name, "
            parameter_missing = True
        elif request.data.get("last_name") is None or request.data.get(
                "last_name") == "":
            parameter_missing_name = parameter_missing_name + "last_name, "
            parameter_missing = True
        elif request.data.get("email") is None or request.data.get(
                "email") == "":
            parameter_missing_name = parameter_missing_name + "email, "
            parameter_missing = True
        elif request.data.get("phone") is None or request.data.get(
                "phone") == "":
            parameter_missing_name = parameter_missing_name + "phone, "
            parameter_missing = True
        elif request.data.get("aadhar") is None or request.data.get(
                "aadhar") == "":
            parameter_missing_name = parameter_missing_name + "aadhar, "
            parameter_missing = True

        if parameter_missing:
            return Response({
                "status": False,
                "status_code": HTTP_204_NO_CONTENT,
                "message": parameter_missing_name + " missing"
            })

        existed_user_email = User.objects.filter(
            email=request.data.get("email")).first()
        if existed_user_email is None:

            existed_user_phone = User.objects.filter(
                phone=request.data.get("phone")).first()
            if existed_user_phone is None:

                existed_user_aadhar = User.objects.filter(
                    aadhar=request.data.get("aadhar")).first()
                if existed_user_aadhar is None:

                    user = User()
                    user.first_name = request.data.get("first_name")
                    user.middle_name = request.data.get("middle_name")
                    user.last_name = request.data.get("last_name")
                    user.email = request.data.get("email")
                    user.phone = request.data.get("phone")
                    user.aadhar = request.data.get("aadhar")
                    user.country = request.data.get("country")
                    user.state = request.data.get("state")
                    user.city = request.data.get("city")
                    user.constitucy = request.data.get("constitucy")
                    user.ward = request.data.get("ward")
                    user.landmark = request.data.get("landmark")
                    user.pincode = request.data.get("pincode")
                    user.gender = request.data.get("gender")
                    user.date_of_birth = request.data.get("date_of_birth")
                    user.role = "member"
                    user.occupation_type = request.data.get("occupation_type")
                    user.occupation_title = request.data.get(
                        "occupation_title")
                    user.save()

                    return Response({
                        "status": True,
                        "status_code": HTTP_200_OK,
                        "message": "User Created.",
                        "user": UserSerializer(user).data
                    })
                else:
                    return Response({
                        "status": False,
                        "status_code": HTTP_302_FOUND,
                        "message": "Aadhar Exist."
                    })
            else:
                return Response({
                    "status": False,
                    "status_code": HTTP_302_FOUND,
                    "message": "Phone Exist."
                })
        else:
            return Response({
                "status": False,
                "status_code": HTTP_302_FOUND,
                "message": "Email Exist."
            })