示例#1
0
 def setUp(self):
     self.userprofile = UserProfile()
     self.userprofile.name("Gustavo Rodrigues Coelho")
     self.userprofile.registration_number = "110030559"
     self.userprofile.category = 'Student'
     self.userprofile.user.username = "******"
     self.userprofile.user.email = "*****@*****.**"
     self.userprofile.user.set_password('123456')
     self.userprofile.save()
     self.client = Client()
     self.factory = RequestFactory()
     self.url = '/user/delete/'
示例#2
0
 def create_michel_temer(self):
     userprofile = UserProfile()
     userprofile.name("Michel Temer")
     userprofile.registration_number = "110030988"
     userprofile.category = 'Student'
     userprofile.user.username = "******"
     userprofile.user.email = "*****@*****.**"
     userprofile.user.set_password('123456')
     if(not self.check_registration_number(userprofile.registration_number)):
         userprofile.registration_number = "101030988"
     userprofile.save()
     userprofile.make_as_academic_staff()
     userprofile.save()
示例#3
0
 def create_fhc(self):
     userprofile = UserProfile()
     userprofile.name("Fernando Henrique Cardoso")
     userprofile.registration_number = "110030989"
     userprofile.category = 'Student'
     userprofile.user.username = "******"
     userprofile.user.email = "*****@*****.**"
     userprofile.user.set_password('123456')
     if(not self.check_registration_number(userprofile.registration_number)):
         userprofile.registration_number = "101030989"
     userprofile.save()
     userprofile.make_as_admin()
     userprofile.save()
示例#4
0
 def create_test_testando(self):
     userprofile = UserProfile()
     userprofile.name("Teste Testando")
     userprofile.registration_number = "110030987"
     userprofile.category = 'Student'
     userprofile.user.username = "******"
     userprofile.user.email = "*****@*****.**"
     userprofile.user.set_password('123456')
     if(not self.check_registration_number(userprofile.registration_number)):
         userprofile.registration_number = "101030987"
     userprofile.save()
     userprofile.make_as_academic_staff()
     userprofile.save()
示例#5
0
def signup_form(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()

            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            email = form.cleaned_data.get('email')
            phone = form.cleaned_data.get('phone')
            user = authenticate(username=username, password=password)
            login(request, user)
            current_user = request.user
            data = UserProfile()
            data.user_id = current_user.id

            data.image = "images.png"
            data.save()
            messages.success(request, 'Account successfully created')
            return HttpResponseRedirect('/')
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/signup')
    form = SignUpForm()
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)

    shipping = 0
    for rs in shopcart:
        shipping = float(2000)

    subtotal = 0
    for rs in shopcart:
        subtotal += rs.product.price * rs.quantity

    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity

    added = 0
    for rs in shopcart:
        added += rs.quantity
    context = {
        'category': category,
        'form': form,
        'total': total,
        'added': added,
        'subtotal': subtotal
    }
    return render(request, 'signup_form.html', context)
示例#6
0
def register_user(step, username, password, registration_number, category):
    user = UserProfile()
    user.user = User()
    user.registration_number = registration_number
    user.user.email = username
    user.user.username = username
    user.user.first_name = "Usuário"
    user.user.set_password(password)
    user.save()
    user.make_as_academic_staff()
    for number, category_type in CATEGORY:
        if category_type == category:
            user.category = number
    user.save()
示例#7
0
文件: views.py 项目: peter-wl/myweb
 def get(self, request):
     for i in range(40, 60):
         user = UserProfile()
         user.username = '******'.format(str(i))
         print type(user.username)
         user.set_password('wl123')
         user.is_active = False
         user.email = 'wl{}@sina.com'.format(str(i))
         user.department = '3'
         user.phone = 13512341230 + i
         user.title = '1'
         user.save()
         user.groups.add(Group.objects.get(pk='3'))
     return JsonResponse('111111')
示例#8
0
def register(request):
    user = User()
    user.username = '******'
    user.password = '******'
    user.phone = '15810888888'
    user.email ='*****@*****.**'
    user.save()

    userprofile = UserProfile()
    userprofile.realname = 'lixiaoxi'
    userprofile.address ='北京'
    userprofile.age =22
    userprofile.user_id = user.id
    userprofile.save()
    return HttpResponse('用户注册成功!!!')
示例#9
0
def home(request):
    if request.method == 'GET':
        return render(request, 'page1.html')
    if request.method == 'POST':
        f_name = request.POST.get('f_name')
        l_name = request.POST.get('l_name')
        contact = request.POST.get('contact')
        email_id = request.POST.get('email_id')
        gender = request.POST.get("gender")
        profile = UserProfile(f_name=f_name,
                              l_name=l_name,
                              ph_no=contact,
                              email=email_id,
                              gender=gender)
        profile.save()
        return redirect('home')
示例#10
0
文件: views.py 项目: peter-wl/myweb
 def post(self, request):
     ret = {}
     ret['status'] = 0
     if not request.user.has_perm('user.manager_permission'):
         ret['status'] = 1
         ret['errmsg'] = u'You not permission'
         return JsonResponse(ret, safe=True)
     obj = UserRegistrationForms(request.POST.dict())
     if obj.is_valid():
         userdict = obj.cleaned_data
         print type(userdict)
         username = userdict.get('r_username', None)
         password = userdict.get('r_password', None)
         email = userdict.get('r_email', None)
         d_id = userdict.get('r_department', None)
         phone = userdict.get('r_phone', None)
         t_id = userdict.get('r_title', None)
         g_id = userdict.get('r_group', None)
         try:
             group = Group.objects.get(pk=g_id)
             user = UserProfile()
             user.username = username
             user.set_password(password)
             user.is_active = False
             user.email = email
             user.department = d_id
             user.title = t_id
             user.phone = phone
             user.save()
             logger.debug('user:{} register {}'.format(
                 username, 'Sucessful'))
             user.groups.add(group)
         except Group.DoesNotExist:
             ret['status'] = 1
             ret['errmsg'] = u"The group does not exist. "
         except IntegrityError as e:
             print e
             ret['status'] = 1
             ret['errmsg'] = u"Username Already exists. Please choose a different Username. "
         except Exception as e:
             print e.args
             ret['status'] = 1
             ret['errmsg'] = e.args
     else:
         ret['status'] = 2
         ret['errmsg'] = obj.errors.as_json()
     return JsonResponse(ret, safe=True)
    def create_users_pdf(self, user):
        museum = self.cleaned_data['museum']
        name = self.cleaned_data['name']

        group = Group(museum=museum, name=name, created_by=user)
        group.save()
        tokens = []
        for x in range(self.cleaned_data['number']):
            profile = UserProfile()
            profile.display_name = f'space cadet {x + 1}'
            profile.save()
            group.profiles.add(profile)
            museum.profiles.add(profile)
            tokens.append(profile.qr_token)

        group.save()
        museum.save()
示例#12
0
 def get(self, request):
     '''
     验证链接是否有效
     '''
     code = request.GET.get("code", "")
     try:
         user_info = red_user_cache.get(code)
         redis_username, redis_password, redis_email = json.loads(user_info)
         user = UserProfile(username=redis_username, email=redis_email)
         user.set_password(redis_password)
         user.has_active = True
         user.greenhand = True
         user.save()
         red_user_cache.delete(code)
     except Exception as e:
         return JsonResponse({"code": 400, "msg": "链接不存在或已失效"})
     return JsonResponse({"code": 200, "msg": "ok"})
示例#13
0
 def post(self, request):
     form = SignUpForm(request.POST)
     if form.is_valid():
         form.save()
         username = form.cleaned_data.get('username')
         raw_password = form.cleaned_data.get('password1')
         user = authenticate(username=username, password=raw_password)
         login(request, user)
         form1 = UserProfile(phone_number='',
                             address='',
                             alternate_email='',
                             owner=user)
         form1.save()
         return redirect('home:all')
     else:
         ctx = {'form': form}
         return render(request, 'user/signup.html', ctx)
示例#14
0
 def post(self, request):
     user = UserProfile()
     cert = Cert()
     pro = Project()
     user.mobile = request.POST.get('mobile', '')
     cert.cert_company = request.POST.get('cert_company', '')
     cert.cert_info = request.POST.get('cert_info', '')
     cert.cert_phone = request.POST.get('cert_phone', '')
     pro.name = request.POST.get('name', '')
     pro.info = request.POST.get('info', '')
     pro.money = request.POST.get('money', '')
     pro.day = request.POST.get('day', '')
     pro.image = request.POST.get('image', '')
     pro.image_detail = request.POST.get('image_detail', '')
     user.save()
     pro.save()
     cert.save()
     return render(request, 'start-step-2.html')
示例#15
0
文件: views.py 项目: whisnos/edp
 def post(self, request):
     print('request.data', request.data)
     resp = {}
     code = request.data.get('code', '')
     if not code or len(code) < 1:
         resp['msg'] = '需要code'
         return Response(resp, 400)
     openid = MemberService.getWeChatOppenid(code)
     if not openid:
         resp['msg'] = '授权失败1'
         return Response(resp, 400)
     bind_info = UserProfile.objects.filter(openid=openid).first()
     if bind_info:
         payload = jwt_payload_handler(bind_info)
         token = jwt_encode_handler(payload)
         resp['msg'] = '登录成功'
         resp['token'] = token
         resp['info'] = {
             'username': bind_info.username,
             'avatar': bind_info.avatar
         }
         return Response(resp, 200)
     nickname = request.data.get('nickName', '')
     sex = request.data.get('gender', '')
     avatar = request.data.get('avatarUrl', '')
     if not nickname or not sex or not avatar:
         resp['msg'] = '非微信授权登录失败'
         return Response(resp, 400)
     member_info = UserProfile()
     member_info.username = nickname
     member_info.sex = sex
     member_info.openid = openid
     member_info.avatar = avatar
     member_info.save()
     payload = jwt_payload_handler(member_info)
     token = jwt_encode_handler(payload)
     resp['msg'] = '登录成功1'
     resp['token'] = token
     resp['info'] = {
         'username': member_info.username,
         'avatar': member_info.avatar
     }
     return Response(resp, 200)
示例#16
0
 def post(self, request):
     register_form = RegisterForm(request.POST)
     if register_form.is_valid():
         user_name = request.POST.get('email', None)
         pass_word = request.POST.get('password', None)
         if UserProfile.objects.filter(email=user_name):
             return render(request, 'register.html', {
                 'register_form': register_form,
                 'msg': '用户已存在'
             })
         user = UserProfile()
         user.email = user_name
         user.password = make_password(pass_word)
         user.save()
         return render(request, 'login.html')
     else:
         return render(request, 'register.html', {
             'register_form': register_form,
         })
示例#17
0
    def post(self, request):
        name = request.POST.get("name")
        print(name)
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            print(form_obj.cleaned_data)
            name = form_obj.cleaned_data["name"]
            password = form_obj.cleaned_data["password"]
            UserProfile(username=name, password=password).save()
            print(UserProfile.objects.all())

            print("form表单验证成功")
            return render(request, "login.html")
        else:
            error = form_obj.errors
            dir(error)
            print(error.items)
            # print(error.data)
            print(error["name"][0])
            return render(request, "register.html", {"error": error})
示例#18
0
 def post(self, request):
     register_form = RegisterForm(request.POST)
     if register_form.is_valid():
         user_name = request.POST.get("username", "")
         try:
             user = UserProfile.objects.get(username=user_name)
         except:
             user = None
         if user != None:
             return render(request, 'duplicat.html', {"msg": "用户名已存在,注册失败"})
         pass_word = request.POST.get("password", "")
         Email = request.POST.get("email", "")
         user_profile = UserProfile()
         user_profile.username = user_name
         user_profile.password = make_password(pass_word)
         user_profile.email = Email
         user_profile.save()
         return render(request, 'ok.html', {"msg": "注册成功,请登录"})
     else:
         return render(request, 'err.html', {"msg": "注册失败"})
示例#19
0
def signup(request):
    error = [False, '']
    form = SignUpForm()
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        userdata = (request.POST['username']).split()
        username = userdata[0]
        first_name = userdata[1]
        last_name = userdata[2]
        mail = request.POST['mail']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        if form.is_valid() and password1 == password2 and len(password1) >= 6:
            user = User.objects.create_user(username, mail, password1)
            user.first_name = first_name
            user.last_name = last_name
            user.is_active = True
            user.save()
            userprofile = UserProfile()
            userprofile.user = user
            userprofile.vk = ''
            userprofile.facebook = ''
            userprofile.twitter = ''
            userprofile.phone = ''
            userprofile.save()
            # Добавление действия в ленту
            addAction(user, 'присоединился к сервису')
            setAch(user, 1)
            return redirect('/auth/in')
        else:
            print('form not valid!')
            error[0] = True
            error[1] = 'Введенные данные содержат ошибку'
    context = {
        "form": form,
        'title': 'Регистрация',
        'error': error[0],
        'error_text': error[1]
    }
    return render(request, 'sign-up.html', context)
示例#20
0
def signup_view(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(request, username=username, password=password)
            login(request, user)
            current_user = request.user
            data = UserProfile()
            data.user_id = current_user.id
            data.save()
            return HttpResponseRedirect('/')

    form = SignUpForm()
    # category = Category.objects.all()
    context = {
        # 'category': category,
        'form': form,
    }
    return render(request, 'signup.html', context)
示例#21
0
    def post(request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            user_name = request.POST.get('email', '')
            if UserProfile.objects.filter(email=user_name):
                return render(request, 'register.html', {
                    'register_form': register_form,
                    'msg': '邮箱已存在'
                })
            pass_word = request.POST.get('password', '')
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)
            user_profile.save()

            send_register_email(user_name, 'register')
            return render(request, 'login.html')
        else:
            return render(request, 'register.html',
                          {'register_form': register_form})
示例#22
0
def get_users_profile(pk):
    """
    Find user profile or create a friend list and user profile if new user.
    """
    requested_user = User.objects.get(pk=pk)

    try:
        user_profile = UserProfile.objects.get(user=requested_user)
    except:
        user_profile = UserProfile(
            user=requested_user,
            age=18,
            profile_image='',
            bio=
            "Click add on your profile image to add a personalised image and bio!",
            premium=False,
        )
        user_profile.save()

        friends_list = Friend(current_user=requested_user, )
        friends_list.save()

    return user_profile
示例#23
0
 def post(self, request):
     register_form = RegisterForm(request.POST)
     if register_form.is_valid():
         username = request.POST.get('username')
         if UserProfile.objects.filter(username=username):
             return render(request, 'reg.html', {
                 'msg': '用户名已存在',
                 'register_form': register_form
             })
         password = request.POST.get('password')
         email = request.POST.get('email')
         types = request.POST.get('type')
         print(types)
         user = UserProfile()
         user.username = username
         user.password = make_password(password=password)
         user.email = email
         user.usertype = types
         user.is_active = False
         user.save()
         send_register_email(email, send_type="register")
         return render(request, 'login.html')
     return render(request, 'reg.html', {'register_form': register_form})
 def setUp(self):
     apartment = PropertyType(
         name = '아파트'
     )
     apartment.save()
     private = PlaceType(
         name = '개인실'
     )
     private.save()
     profile = UserProfile(
         profile_header = "hi"
     )
     profile.save()
     user = User(
         username = '******',
         fullname = 'junepyo',
         is_host  = True,
         profile  = profile
     )
     user.save()
     room = Room(
         title            = "World's best house for nomad coders",
         address          = "Gangnam-gu, 서울, 대한민국",
         description      = "5G internet, complimentary thunderbolt cables, 3 minutes walk to Seonleung station,\
             house equipment include iMac, 16-inch MacBook pro, and Keychron wireless mechanical keyboard.",
         price            = 130.00,
         host             = user,
         max_capacity     = 4,
         check_in         = datetime.time(15-00-00),
         check_out        = datetime.time(12-00-00),
         latitude         = 37.501670,
         longitude        = 127.035530,
         monthly_stay     = True,
         place_type       = private,
         property_type    = apartment
     )
     room.save()
示例#25
0
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            user_name = request.POST.get("email", "")

            if UserProfile.objects.filter(email=user_name):
                # 验证用户名是否已经存在
                return render(request, "user_register.html",
                              {"register_form": register_form},
                              {"msg": "用户名已经存在"})

            pass_word = request.POST.get("password", "")
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)
            user_profile.save()

            # send_register_email(user_name, "register")
            return render(request, "user_login.html")
        else:
            return render(request, "user_register.html",
                          {"register_form": register_form})
示例#26
0
文件: views.py 项目: 402test/WangYiTu
    def post(self,request):
        regiter_form = RegisterForm(request.POST)
        if regiter_form.is_valid():
            user_name = request.POST.get('email','')
            if UserProfile.objects.filter(email=user_name):
                return render(request, 'register.html', {'msg': 'already','regiter_form':regiter_form})

            #  发送邮件
            email_res  = send_register_email(user_name)
            if not email_res:
                return render(request, 'register.html', {'msg': 'error', 'regiter_form': regiter_form})
            #  保存到数据库
            pass_word = request.POST.get("password", "")
            user_profile = UserProfile()
            user_profile.username = user_name
            user_profile.email = user_name
            user_profile.is_active = False
            user_profile.password = make_password(pass_word)
            user_profile.save()


            return render(request, "register.html",{'msg':'true' ,'regiter_form':regiter_form})
        else:
            return render(request,'register.html',{'regiter_form':regiter_form})
示例#27
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)

            current_user = request.user
            data = UserProfile()
            data.user_id = current_user.id
            data.image = r'C:\Users\Nisarg Trivedi\PycharmProjects\MyAwesomeCart\mac\shop\static\user.png'
            data.save()
            messages.success(request, 'Your Account Has Been Created')
            return HttpResponseRedirect('/')
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/signup')
    else:
        form = SignUpForm()

    return render(request, 'shop/signup.html', {'form': form})
示例#28
0
def signup_form(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)

            current_user = request.user
            data = UserProfile()
            data.user_id = current_user.id
            data.image = "images/users/users.png"
            data.save()
            messages.success(request, 'Your account has been created!')
            return HttpResponseRedirect('/')
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/signup')

    form = SignUpForm()
    context = {'form': form}
    return render(request, 'signup_form.html', context)
示例#29
0
文件: views.py 项目: benmed07/NewWeb
def signup_form(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save() #Save user form data to user table
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password) #login after registration
            login(request, user)

            # CREATE DATA IN PROFILE TABLE FOR USER
            current_user = request.user
            data = UserProfile()
            data.user_id = current_user.id
            data.image = "images/users/user.png"
            data.save()

            # CREATE DATA IN PROFILE PROFESSIONNEL TABLE FOR USER
            current_user = request.user
            data = ProfilePro()
            data.user_id = current_user.id
            data.image = "images/users/user.png"
            data.save()
            messages.success(request, 'Your account has been created !, veuillez remplir votre profile.')

            return HttpResponseRedirect('/user/update')
        else:
            messages.warning(request,form.errors)
            return HttpResponseRedirect('/signup')

    category = Category.objects.all()
    form = SignUpForm()
    context = {'category': category,
               'form': form
               }
    return render(request, 'signup_form.html', context)
示例#30
0
        'is_superuser': False,
        'is_staff': False,
        'is_active': True
    },
    {
        'username': '******',
        'nickname': '王五',
        'avatar': 'user/avatars/3.jpg',
        'is_superuser': False,
        'is_staff': False,
        'is_active': True
    },
    {
        'username': '******',
        'nickname': '赵六',
        'avatar': 'user/avatars/4.jpg',
        'is_superuser': False,
        'is_staff': False,
        'is_active': True
    },
]

for item in users_data:
    if not UserProfile.objects.filter(username=item['username']).exists():
        user = UserProfile(**item)
        user.password = make_password('123')
        user.save()
        print(user.id, '--', user.username, '--', user.password)
    else:
        print(item['username'], '用户名已存在!')