Exemplo n.º 1
0
def register(request):
    if (request.method == 'POST'):
        print("register function called from authentication ...")
        # uname = request.POST['uname']
        email = request.POST['email']
        # fname = request.POST['fname']
        # lname = request.POST['lname']
        password = request.POST['password']
        confirmPassword = request.POST['confirmPassword']

        if (password == confirmPassword):
            #print "password == confirmPassword"
            if (User.objects.filter(username=email).exists()):
                print("Error , acout alreasy exists")
            else:
                user = User.objects.create_user(username=email,
                                                password=password)
                user.save()
                profile = Profile(user=user)
                profile.save()
                user = authenticate(username=email, password=password)
                if user is not None:
                    if user.is_active:
                        auth_login(request, user)
                        return redirect('/discover')
                else:
                    return redirect('/authentication/login')
        else:
            print("password and confirmation password dont match !")
        return redirect('/authentication/login')
Exemplo n.º 2
0
    def post(self, request, format=None):
        code = request.data.get('code')
        (resp_headers, content) = httplib2.Http(".cache").request(
            f'https://graph.facebook.com/me?fields=id,name,email,picture.width(96).height(96)&access_token={code}',
            "GET")
        facebook_id = json.loads(content).get('id')
        username = json.loads(content).get('email')
        full_name = json.loads(content).get('name')
        avatar = json.loads(content).get('picture').get('data').get('url')
        try:
            user = User.objects.get(profile__facebook_id=facebook_id)
            token, created = Token.objects.get_or_create(user=user)
            return Response({'token': token.key}, status=status.HTTP_200_OK)
        except:
            pass

        try:
            User.objects.get(username=username)
            return Response(
                {'login_error': 'There was an account with this username'},
                status=status.HTTP_400_BAD_REQUEST)
        except:
            pass

        user = User.objects.create_user(username=username)
        profile = Profile(full_name=full_name,
                          avatar=avatar,
                          facebook_id=facebook_id,
                          password_set=False,
                          user=user)
        profile.save()
        token, created = Token.objects.get_or_create(user=user)
        return Response({'token': token.key}, status=status.HTTP_201_CREATED)
Exemplo n.º 3
0
    def post(self, request, format=None):
        code = request.data.get('code')
        credentials = client.credentials_from_clientsecrets_and_code(
            settings.CLIENT_SECRET_FILE, ['profile', 'email'], code)
        google_id = credentials.id_token.get('sub')
        username = credentials.id_token.get('email')
        full_name = credentials.id_token.get('name')
        avatar = credentials.id_token.get('picture')
        try:
            user = User.objects.get(profile__google_id=google_id)
            token, created = Token.objects.get_or_create(user=user)
            return Response({'token': token.key}, status=status.HTTP_200_OK)
        except:
            pass

        try:
            User.objects.get(username=username)
            return Response(
                {'login_error': 'There was an account with this username'},
                status=status.HTTP_400_BAD_REQUEST)
        except:
            pass

        user = User.objects.create_user(username=username)
        profile = Profile(full_name=full_name,
                          avatar=avatar,
                          google_id=google_id,
                          password_set=False,
                          user=user)
        profile.save()
        token, created = Token.objects.get_or_create(user=user)
        return Response({'token': token.key}, status=status.HTTP_201_CREATED)
Exemplo n.º 4
0
 def post(self, request, format=None):
     username = request.data.get('username')
     password = request.data.get('password')
     full_name = request.data.get('full_name')
     user = User.objects.create_user(username=username, password=password)
     profile = Profile(full_name=full_name, password_set=True, user=user)
     profile.save()
     token, created = Token.objects.get_or_create(user=user)
     return Response({'token': token.key}, status=status.HTTP_201_CREATED)
def save_profile(backend, user, response, *args, **kwargs):
    img_url = 'http://graph.facebook.com/%s/picture?type=large' \
        % response['id']

    try:
        profile = user.profile
    except:
        profile = Profile(user_id=user.id)
    profile.picture = img_url
    profile.save()
Exemplo n.º 6
0
 def add(self, role, org_unit_id, first_name, last_name):
     profile = Profile(first_name=first_name, last_name=last_name)
     profile.save()
     work_unit = OrganizationUnitRepo(user=self.user).organizationunit(
         organizationunit_id=org_unit_id)
     if work_unit is not None:
         employee = Employee(profile=profile,
                             work_unit=work_unit,
                             role=role)
         employee.save()
         return employee
Exemplo n.º 7
0
    def register(self, username, password, first_name, last_name, region_id):
        if not self.check_availabe_username(username):
            return None
        user = User.objects.create_user(username=username,
                                        email='*****@*****.**',
                                        password=password)

        # Update fields and then save again
        user.first_name = first_name
        user.last_name = last_name
        user.save()
        profile = Profile(user=user,
                          first_name=first_name,
                          mobile='',
                          last_name=last_name,
                          region_id=region_id)
        profile.save()
        return profile
Exemplo n.º 8
0
def shop(request):
    shops = Profile.get_shop()
    paginator = Paginator(shops, 10)
    page = request.GET.get('page')
    try:
        shops = paginator.page(page)
    except PageNotAnInteger:
        shops = paginator.page(1)
    except EmptyPage:
        shops = paginator.page(paginator.num_pages)
    return render(request, 'useradmin/shop_list.html', {'shops': shops})
Exemplo n.º 9
0
def company(request):
    companies = Profile.get_company()
    paginator = Paginator(companies, 10)
    page = request.GET.get('page')
    try:
        companies = paginator.page(page)
    except PageNotAnInteger:
        companies = paginator.page(1)
    except EmptyPage:
        companies = paginator.page(paginator.num_pages)
    return render(request, 'useradmin/company_list.html',
                  {'companies': companies})
Exemplo n.º 10
0
def admin_home(request):
    unapproved_profiles = Profile.get_unapproved()
    paginator = Paginator(unapproved_profiles, 10)
    page = request.GET.get('page')
    try:
        unapproved_profiles = paginator.page(page)
    except PageNotAnInteger:
        unapproved_profiles = paginator.page(1)
    except EmptyPage:
        unapproved_profiles = paginator.page(paginator.num_pages)
    return render(request, 'useradmin/home.html',
                  {'unapproved_profiles': unapproved_profiles})
Exemplo n.º 11
0
    def put(self, request, profile_id):

        try:
            name = str(request.data.get('name', ''))
            family_name = str(request.data.get('family_name', ''))
            age = int(request.data.get('age', 0))
            gender = (request.data.get('gender'))

            if gender:
                gender = bool(gender)

        except(ValueError, KeyError):
            return Response({'error': 'data is incorrect'}, status=400)

        try:
            profile = Profile.objects.get(id = profile_id)
        except(Profile.DoesNotExist()):
            return Response({
                "message": "profile is not excist"
            })
        if name:
            profile.name = name

        if family_name:
            profile.f_name = family_name

        if age:
            profile.age = age

        if gender is not None:
            profile.gender = gender

        profile.save()
        return Response({
            "massage": "profile "+str(profile_id)+" is edited"
        })
Exemplo n.º 12
0
    def signup(self, request, user):

        # Save your profile
        profile = Profile()
        profile.user = user
        profile.first_name = self.cleaned_data['first_name']
        profile.last_name = self.cleaned_data['last_name']
        profile.organization = self.cleaned_data['organization']
        profile.location_city = self.cleaned_data['location_city']
        profile.location_state = self.cleaned_data['location_state']
        #profile.terms_agree = self.cleaned_data['terms_agree']
        profile.main_picture = self.cleaned_data['main_picture']

        # Save your user and profile
        user.save()
        profile.save()