Ejemplo n.º 1
0
def editnumber(request):
    data = {}
    if request.method == 'POST':
        number = request.POST['number']

        user = usersdetails.objects.filter(users=request.user).first()
        userwithnumber = usersdetails.objects.filter(
            Q(phnumber1=(number)) | Q(phnumber2=(number))).first()

        if userwithnumber == None:
            otp = sendsms(number)
            data['otpsend'] = 1
            response = HttpResponse(json.dumps(data),
                                    content_type="application/json")
            response.set_cookie('XMHDABOOKCC', otp)
            return response
        else:
            if userwithnumber.users == request.user:
                if number == user.phnumber1:
                    data['nochange'] = 1
                    return HttpResponse(json.dumps(data),
                                        content_type="application/json")
                elif number == user.phnumber2:
                    user.phnumber1 = user.phnumber2
                    user.save()
                    data['changesuccess'] = 1
                    return HttpResponse(json.dumps(data),
                                        content_type="application/json")
            else:
                data['userexits'] = 1
                return HttpResponse(json.dumps(data),
                                    content_type="application/json")
Ejemplo n.º 2
0
def editpassword(request):
    data = {}
    if request.method == 'POST':
        currentpassword = request.POST['currentpassword']
        newpassword = request.POST['newpassword']
        confirmnewpassword = request.POST['confirmnewpassword']

        user = User.objects.filter(email=request.user.email).first()

        if check_password(currentpassword, request.user.password) == True:
            if newpassword == confirmnewpassword:
                user.set_password(newpassword)
                user.save()
                login(request, user)
                data['valid'] = 1
                return HttpResponse(json.dumps(data),
                                    content_type="application/json")
            else:
                data['nomatch'] = 1
                return HttpResponse(json.dumps(data),
                                    content_type="application/json")
        else:
            data['notvalid'] = 1
            return HttpResponse(json.dumps(data),
                                content_type="application/json")
Ejemplo n.º 3
0
def uservalidation(request, token):
    s = serializer(SECRET_KEY)
    try:
        email = s.loads(token)['email']
        name = s.loads(token)['name']
        phnumber = s.loads(token)['phnumber']
        password = s.loads(token)['password']
        user = User.objects.create_user(unique_username_id_generator(name),
                                        email, password)
        if len(name.split(' ')) >= 2:
            user.first_name = name.split(' ')[0]
            user.last_name = name.split(' ')[1]
            user.save()
        else:
            user.first_name = name
            user.save()

        obj = usersdetails(uid=unique_username_id_generator(name),
                           phnumber1=(phnumber),
                           users=user)
        obj.save()
        userwallet = wallet(walletid=unique_wallet_id_generator(name),
                            user=user,
                            userdetail=obj)
        userwallet.save()
        messages.success(request,
                         'Your Account has been created successfully.')
        return redirect('home')
    except:
        d = User.objects.filter(password='')
        for i in d:
            i.delete()
        return HttpResponse(
            '<h1>Your Verification link is expired plese sigup again</h1>')
Ejemplo n.º 4
0
def setprofileimage(request):
    data = {}
    if request.method == 'POST':
        profileimage = request.FILES['myfile']
        user = usersdetails.objects.filter(users=request.user).first()
        user.userimage = profileimage
        user.save()
        data['valid'] = 1
        return HttpResponse(json.dumps(data), content_type="application/json")
Ejemplo n.º 5
0
def emailreset(request, token):
    s = serializer(SECRET_KEY)
    try:
        newemail = s.loads(token)['newemail']
        email = s.loads(token)['email']
        user = User.objects.filter(email=email).first()
        user.email = newemail
        user.save()
        messages.success(request, 'Your Email is changed  successfully.')
        return redirect('home')
    except:
        return HttpResponse('<h1>Your Email reseting  link is expired.</h1>')
Ejemplo n.º 6
0
def checkotp(request):
    data = {}
    if request.method == 'POST':
        otp = request.POST['otp']
        number = request.POST['number']

        if request.COOKIES['XMHDABOOKCC'] == otp:
            user = usersdetails.objects.filter(users=request.user).first()
            user.phnumber1 = number
            user.save()
            data['valid'] = 1
            return HttpResponse(json.dumps(data),
                                content_type="application/json")
        else:
            data['notvalid'] = 1
            return HttpResponse(json.dumps(data),
                                content_type="application/json")
Ejemplo n.º 7
0
def resetmypassword(request, token):
    s = serializer(SECRET_KEY)
    try:
        email = s.loads(token)['email']
        context = {}
        if request.method == 'POST':
            password = request.POST['password']
            user = User.objects.filter(email=email).first()
            user.set_password(password)
            user.save()
            messages.success(
                request, 'Your Account Password has Reseted successfully.')
            login(request, user)
            return redirect('home')
        context['email'] = email
        return render(request, 'users/resetmypassword.html', context=context)
    except:
        messages.success(
            request,
            'Your Password Reset  link is expired please generate New one.')
        return redirect('home')
Ejemplo n.º 8
0
def editname(request):
    data = {}
    if request.method == 'POST':
        fullname = request.POST['fullname']
        user = User.objects.filter(email=request.user.email).first()
        if fullname.replace(' ', '').isalpha():
            fullname = fullname.split(' ')
            if len(fullname) == 2:
                user.first_name = fullname[0]
                user.last_name = fullname[1]
                user.save()
            else:
                user.first_name = fullname[0]
                user.save()
            data['valid'] = 1
            return HttpResponse(json.dumps(data),
                                content_type="application/json")
        else:
            data['notvalid'] = 1
            return HttpResponse(json.dumps(data),
                                content_type="application/json")