Example #1
0
def create(request):
    dict = {}
    if request.method == 'POST':
        req = simplejson.loads(request.raw_post_data)
        rusername = req['username']
        rname = req['name']
        rphonenumber = req['phonenumber']
        raddress = req['address']
        rpassword = req['password']
        b = user.objects.filter(username=rusername)
        if (len(b) != 0):
            dict['status'] = 'a'  #如果username已经存在,返回状态a
        else:
            try:
                p1 = user(username=rusername,
                          name=rname,
                          phonenumber=rphonenumber,
                          address=raddress,
                          password=rpassword)
                p1.save()
                dict['status'] = 'y'
            except:
                dict['status'] = 'n'
        x = simplejson.dumps(dict)
        return HttpResponse(x)
    dict['status'] = 'w'
    x = simplejson.dumps(dict)
    return HttpResponse(x)
Example #2
0
    def get(self, request):
        if request.user.is_authenticated:
            if not user.objects.filter(user_reg=request.user).exists():
                #если нет записи в профиле
                #создаем новую
                profil = user()
                profil.user_reg = request.user
                profil.save()

            return render(request, self.template_name, {})
        else:
            return render(request, self.template_name, {})
Example #3
0
 def get(self, request):
     if request.user.is_authenticated:
         if not user.objects.filter(user_reg=request.user).exists():
             #если нет записи в профиле
             #создаем новую
             profil = user()
             profil.user_reg = request.user
             profil.save()
         userobj = user.objects.get(user_reg=request.user)
         profilform = FillProfile(instance=userobj)
         return render(request,
                       'users/updateprofil.html',
                       context={'form': profilform})
Example #4
0
def Regestrations(request, game, tour): 
    context = {}
    pgame = Game.objects.get(pk=int(game))
    userobj = user.objects.filter(user = request.user, games = pgame).first()
    tournament = tournaments.objects.filter(tourid = int(tour)).first()
    solouser = regestration.objects.filter(user=userobj, tournament = tournament).first()
    userp = usersdetails.objects.filter(users=request.user).first()
    if request.method == 'POST':
        username = request.POST['username']
        number = request.POST['number']
        if userobj == None:
            userobj = user(user= request.user, username = username, games= pgame )
            userobj.save()
        else:
            userobj.username = username
            userobj.save()
        if str(number) != userp.phnumber1:
            userp.phnumber1 = number
            userp.save()
        if tournament.availseats > 0:
            sid = unique_solo_id_generator(userobj.user.first_name)
            regester = regestration(sid=sid, tournament= tournament, user = userobj, regestrationfee = tournament.entryfee)
            regester.save()
            if tournament.entryfee < 1: # if no entry fee then simply confirm the user regestration
                tour = tournament
                tour.availseats -= 1
                tour.occupiedseats += 1
                regester.status = 1
                regester.save()
                tour.save()
                messages.success(request,'Congrats, You have been  registered for this tournament, RoomID AND password will be send to You before 15min, of tournament starting time.')
                return redirect('home')
            return redirect('Regestrationprox', regestrationid = regester.sid)
        else:
            return HttpResponse('<h1>Sorry, Regestration has been Full. Please apply for next tournament</h1>')
    if solouser != None:
        if solouser.status == 0:
            return redirect('Regestrationprox', regestrationid = solouser.sid)
        if solouser.status == 1:
            context['userisregestered'] = 1
            context['tournament'] = solouser.tournament
            messages.success(request,f'You are already registered, for {solouser.tournament.tourname} tournament,Besofluck and see you in the tournament.')
            return redirect('home')
    if userobj != None:
        context['username'] = userobj.username
    if tournament.tournamenttype > 0:
        context['multipleuser'] = 1
    context['userphone'] = userp.phnumber1
    return render(request,'tournaments/SoloRegestration.html',context=context)
Example #5
0
def register(request):
    """
    ...The register user function...
    """
    try:
        fn = request.POST["name"]
        em = request.POST["email"]
        pw = hashlib.md5(hashlib.sha512(request.POST["pass"]).digest()).hexdigest()
    except KeyError:
        return HttpResponseRedirect(reverse('home'))
    else:
        dt = timezone.now()
        user_add = user(fullName=fn, email=em, password=pw, dateJoined=dt)
        user_add.save()
        request.session['userId'] = user_add.id
        request.session['userName'] = user.fullName
        return HttpResponseRedirect(reverse('home'))
Example #6
0
    def create(self):
        data = {}

        try:
            data = self._validate_username()

            if len(data) == 0:
                data = self._validate_password()

            if len(data) == 0:
                data = self._validate_firstname()

            if len(data) == 0:
                data = self._validate_surname()

            if len(data) == 0:
                data = self._validate_calories()

            if len(data) == 0:
                new_user = user.objects.filter(username=self.username,
                                               active=True)

                if len(new_user) > 0:
                    self.status = 409
                    data['message'] = 'Username already exists'
                else:
                    new_user = user()
                    new_user.username = self.username
                    new_user.password = self.password
                    new_user.firstname = self.firstname
                    new_user.surname = self.surname
                    new_user.calories = self.calories
                    new_user.save()

                    self.status = 201
                    data['message'] = 'User successfully created'
                    data['data'] = new_user.get_fields()
        except:
            self.status = 500
            data['message'] = 'An internal server error occured'

        return data
Example #7
0
def registration(request):
    name = request.POST['name']
    email = request.POST['email']
    password = request.POST['password']

    if name != '' and email != '' and password != '':
        try:
            officer = user.objects.get(email = email)
        except ObjectDoesNotExist:
            officer = user(name = name, email = email, password = password)
            officer.save()
            try:
                officer = user.objects.get(email = email)
            except ObjectDoesNotExist:
                msg = 'Try Later.'
            else:
                msg = 'Congratualtions!! Log in ...'
        else:
            msg = 'Email already exists. Try another ...'
    else:
        msg = 'Fill empty fields.'
    return render(request, 'user/home.html', {'reg_msg': msg,})
Example #8
0
def usocialogin(request):
    if not request.method == "POST":
        return JsonResponse({"message": "Request should be POST"}, status=400)
    data = json.loads(request.body)
    if not all(elm in list(data.keys()) for elm in ['uid', 'provider']):
        return JsonResponse(
            {"message": "required details are not provided not provided"},
            status=400)
    if not usocial.objects.filter(uid=data['uid'],
                                  provider=data['provider']).exists():
        if 'email' not in data.keys():
            return JsonResponse({"message": "Email Required, no object found"},
                                status=200)
        else:
            if user.objects.filter(email=data['email']).exists():
                luser = user.objects.get(email=data['email'])
                newi = usocial(uid=data['uid'],
                               provider=data['provider'],
                               user=luser)
                newi.save()
                return JsonResponse(
                    {"token": get_or_create_token(data['email'])}, status=200)
            else:
                email = data['email']
                password = passgen().make_random_password()
                username = create_unique_username(email)
                cuser = user(username=username, email=email, password=password)
                cuser.save()
                newi = usocial(uid=data['uid'],
                               provider=data['provider'],
                               user=cuser)
                newi.save()
                return JsonResponse(
                    {"token": get_or_create_token(data['email'])}, status=200)
    else:
        k = usocial.objects.get(uid=data['uid'], provider=data['provider'])
        return JsonResponse({"token": get_or_create_token(k.user.email)},
                            status=200)
Example #9
0
def create(request):
	dict = {}
	if request.method == 'POST':
		req = simplejson.loads(request.raw_post_data)
		rusername = req['username']
		rname = req['name']
		rphonenumber = req['phonenumber']
		raddress = req['address']
		rpassword = req['password']
		b = user.objects.filter(username=rusername)
		if(len(b) != 0):
			dict['status'] = 'a'#如果username已经存在,返回状态a
		else:
			try:
				p1 = user(username = rusername,name = rname,phonenumber = rphonenumber,address = raddress,password = rpassword)
				p1.save()
				dict['status'] = 'y'
			except:	
				dict['status'] = 'n'
		x = simplejson.dumps(dict)
		return HttpResponse(x)
	dict['status'] = 'w'
	x = simplejson.dumps(dict)
	return HttpResponse(x)