Beispiel #1
0
def signin(request):
    """ Sign up view """
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['passwd']
        password_confirmation = request.POST['passwd_confirmation']

        if password != password_confirmation:
            return render(request, 'login/signin.html', {'error': 'Password do not match'})

        try:
            user = User.objects.create_user(username=username, password=password)
            user.first_name = request.POST['first_name']
            user.last_name = request.POST['last_name']
            user.email = request.POST['email']
            user.save()
        except IntegrityError:
            return render(request, 'login/signin.html', {'error': 'Username already taken'})

        try:
            profile = Profile(user= user, type_user='******',birthdate=request.POST['birthdate'])
            card = Card.objects.all()[:3]
            profile.save()
            for carta in card:    
                profile.cards.add(carta)
                profile.save()
        except IntegrityError:
            render(request, 'login/signin.html', {'error': 'Username already taken'})
        
        return redirect('login')
        
    x = datetime.datetime.now()
    today = x.strftime("%Y")+"-"+x.strftime("%m")+"-"+x.strftime("%d")
    return render(request,'login/signin.html',{'today':today})
Beispiel #2
0
def create_userprofile_with_github_user_info(request):

    headers = {'Authorization': '{} {}'.format(request.session.get('token_type'), request.session.get('access_token'))}
    json_response = requests.get('https://api.github.com/user', headers=headers).json()
    
    github_id = extract_from(json_response, "id")
    name = extract_from(json_response, "name")
    avatar_url = extract_from(json_response, "avatar_url")
    email = extract_from(json_response, "email")

    print("github id {} - name {} - avatar_url {} - email {}".format(github_id, name, avatar_url, email))
    
    try:
        new_user = User() 
        new_user.authentication_id = github_id
        new_user.name = name
        new_user.email = email
        new_user.save()

        new_profile = Profile()
        new_profile.user_id = new_user.id
        new_profile.avatar_url = avatar_url

        new_profile.User = new_user
        new_profile.save()
        request.session['username'] = name

        content = {'githubapi.profile_creation': 'User created and Profille authomatic filled with user Github public information'}
        return Response(content, status=status.HTTP_201_CREATED)
    except:
        content = {'githubapi.profile_creation': 'something went bad'}
        return Response(content, status=status.HTTP_409_CONFLICT)
Beispiel #3
0
def RegisterInformation(information):
    stu_num = information['stu_num']
    stu_name = information['stu_name']
    first_major = information['first_major']
    second_major = information['second_major']
    all_rec = information['all_rec']
    # 신입생 전공 비어있는 경우 직접 할당
    if not first_major:
        first_major = '글로벌리더십'

    try:
        user = User.objects.create_user(username=stu_num)
        user.save()
        get_user = User.objects.get(username=stu_num)
        profile = Profile(User=get_user,
                          FirstMajor=first_major,
                          SecondMajor=second_major,
                          UserName=stu_name,
                          LectureRecord=all_rec)
        profile.save()
        return user
    except:
        # User를 만들었으나 Profile에서 실패할 경우 User만 등록되는 겨우가 발생함.
        # 예외처리로 User만 등록되었을 때를 위한 처리
        e_user = User.objects.filter(username=stu_num)
        if e_user:
            e_user.delete()

        if request.flavour == 'full':
            return render(request, 'html/stu_num_duplicate.html')
        else:
            return render(request,
                          'm_skins/m_html/stu_num_duplicate.html')  # m_skin 없음
Beispiel #4
0
 def test_profile_creation(self):
     new_profile = Profile()
     new_profile.user = User.objects.get(id=1)
     new_profile.type = 'TM'
     new_profile.email = '*****@*****.**'
     new_profile.avatar_url = 'http://jenkins.com/pictures/leroy/1'
     new_profile.save()
     self.assertIsNotNone(new_profile,
                          "Profile should be created sucessfully")
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data)
        serializer.is_valid(raise_exception=True)

        user = serializer.save()

        Token.objects.filter(user=user).delete()
        token, created = Token.objects.get_or_create(user=user)

        data = {"id": user.id, "success": True, "token": token.key}

        profile = Profile(user=user)
        profile = update_profile(profile, serializer.validated_data)
        profile.save()

        return Response(data, status=status.HTTP_201_CREATED)
Beispiel #6
0
def RegisterInfo(request):
    if request.method == 'POST':
        stu_num = request.POST['stu_num']
        stu_name = request.POST['stu_name']
        first_major = request.POST['first_major']
        second_major = request.POST.get('second_major', 'None')
        all_rec = request.POST['all_rec']
        # 신입생 전공 비어있는 경우 직접 할당
        if not first_major:
            first_major = '글로벌리더십'

        try:
            user = User.objects.create_user(username=stu_num)
            user.save()
            get_user = User.objects.get(username=stu_num)
            profile = Profile(User=get_user,
                              FirstMajor=first_major,
                              SecondMajor=second_major,
                              UserName=stu_name,
                              LectureRecord=all_rec)
            profile.save()

        except:
            # User를 만들었으나 Profile에서 실패할 경우 User만 등록되는 겨우가 발생함.
            # 예외처리로 User만 등록되었을 때를 위한 처리
            e_user = User.objects.filter(username=stu_num)
            if e_user:
                e_user.delete()

            if request.flavour == 'full':
                return render(request, 'html/stu_num_duplicate.html')
            else:
                return render(
                    request,
                    'm_skins/m_html/stu_num_duplicate.html')  # m_skin 없음

        if request.flavour == 'full':
            return loginCheck(request)
        else:
            return loginCheck(request)

    else:
        if request.flavour == 'full':
            return render(request, 'html/login.html')
        else:
            return render(request, 'm_skins/m_html/login.html')
Beispiel #7
0
def Register(request):
    if request.method == 'POST':
        stu_num = request.POST['stu_num']
        user_pw = request.POST['user_pw']
        user_email = request.POST['user_email']
        user_name = request.POST['user_name']
        first_major = request.POST['first_major']
        second_major = request.POST.get('second_major', 'None')
        all_rec = request.POST['all_rec']

        try:
            user = User.objects.create_user(username=stu_num,
                                            password=user_pw,
                                            email=user_email)
            user.save()
            get_user = User.objects.get(username=stu_num)
            profile = Profile(User=get_user,
                              FirstMajor=first_major,
                              SecondMajor=second_major,
                              UserName=user_name,
                              LectureRecord=all_rec)
            profile.save()
        except:
            # User를 만들었으나 Profile에서 실패할 경우 User만 등록되는 겨우가 발생함.
            # 예외처리로 User만 등록되었을 때를 위한 처리
            e_user = User.objects.filter(username=stu_num)
            if e_user:
                e_user.delete()
            if request.flavour == 'full':
                render(request, 'html/error.html')
            else:
                render(request, 'm_skins/m_html/error.html')
        if request.flavour == 'full':
            return HttpResponseRedirect('/')
        else:
            return render(request, 'm_skins/m_html/login.html')

    else:
        if request.flavour == 'full':
            return render(request, 'html/login.html')
        else:
            return render(request, 'm_skins/m_html/login.html')
Beispiel #8
0
def SignUp(request):
    if request.method == 'POST':
        user_name = request.POST.get('Name', '')
        Fname = request.POST.get('Fname', '')
        Lname = request.POST.get('Lname', '')
        Password = request.POST.get('Password', '')
        re_Password = request.POST.get('re_Password', '')
        Email = request.POST.get('Email', '')
        cnic = request.POST.get('cnic', '')
        print(type(user_name), type(Password))
        print(Email)
        if not (ord(user_name[0]) >= 65 and (ord(user_name[0]) <= 122)):
            messages.info(request,
                          'First or Last letter should not be integer ')
            return redirect("SignUp")
        # user = authenticate(username=user_name, password=Password)
        if User.objects.filter(username=user_name).exists():
            messages.info(request, 'user already exits')
            return redirect("SignUp")
        elif User.objects.filter(email=Email).exists():
            messages.info(request, 'Email already taken')
            return redirect("SignUp")
        elif Password != re_Password:
            messages.info(request, 'password is not matching')
            return redirect("SignUp")
        elif len(Password) < 8:
            messages.info(request, 'password is too short')
            return redirect("SignUp")
        else:
            user1 = User.objects.create_user(user_name,
                                             Email,
                                             Password,
                                             first_name=Fname,
                                             last_name=Lname)
            print(User.objects.all())
            profiel = Profile(user=user1, CNIC=cnic)
            profiel.save()
            messages.info(request, 'Welcome ' + user_name)
            return redirect("SignIn")
    else:
        return render(request, 'SignUp.html')
def Register(request):
    if request.method=='POST':
        Name = request.POST['inputName']
        stu_num = request.POST['inputStudentId']
        Phone =request.POST['Phone']
        password = request.POST['inputPassword']
        question = request.POST['question']
        answer = request.POST['answer']
        
        try:
            user = User.objects.create_user(username=stu_num, password=password, email="")
            user.save()
            get_user = User.objects.get(username=stu_num)
            
            profile = Profile(User=get_user, Name=Name, phone=Phone, hint=question, answer=answer)
            profile.save()
            
            return render_to_response('html/login.html')


        except:
            return HttpResponseRedirect("/Register")
Beispiel #10
0
def twitter_authenticated(request):
    # Step 1. Use the request token in the session to build a new client.
    print "Oauth_token: %s" % request.GET['oauth_token']
    print "Previous oauth_token: %s" % request.session['request_token']['oauth_token']
    if request.GET['oauth_token'] != request.session['request_token']['oauth_token']:
        raise Exception("Invalid response from Twitter. oauth_token doesn't match\
        previous outh token")

    token = oauth.Token(request.session['request_token']['oauth_token'],
            request.session['request_token']['oauth_token_secret'])
    client = oauth.Client(consumer, token)

#    token = oauth.Token(request.session['request_token']['oauth_token'],
#            request.session['request_token']['oauth_token_secret'])
#    client = oauth.Client(consumer, token)

    # Step 2. Request the authorized access token from Twitter.
    print "Oauth_verifier: %s" % request.GET['oauth_verifier']
    body = "oauth_verifier=%s" % request.GET['oauth_verifier']
    resp, content = client.request(access_token_url, "POST", body=body)
    if resp['status'] != '200':
        print content
        raise Exception("Invalid response from Twitter.")

    """ This is what you'll get back from Twitter. Note that it includes the
        user's user_id and screen_name.
            {
                'oauth_token_secret': 'IcJXPiJh8be3BjDWW50uCY31chyhsMHEhqJVsphC3M',
                 'user_id': '120889797',
                 'oauth_token': '120889797-H5zNnM3qE0iFoTTpNEHIz3noL9FKzXiOxwtnyVOD',
                 'screen_name': 'heyismysiteup'
             }
                """
    access_token = dict(cgi.parse_qsl(content))

    # Step 3. Lookup the user or create them if they don't exist.
    try:
        user = User.objects.get(username=access_token['screen_name'])
	print "user existed"
    except User.DoesNotExist:
        # When creating the user I just use their [email protected]
        # for their email and the oauth_token_secret for their password.
        # These two things will likely never be used. Alternatively, you
        # can prompt them for their email here. Either way, the password
        # should never be used.
        user = User.objects.create_user(access_token['screen_name'],
                '*****@*****.**' % access_token['screen_name'],
                access_token['oauth_token_secret'])
	user.save()
	print "user didn't exist"

        # Save our permanent token and secret for later.
    profile = Profile()
    profile.user = user
    profile.oauth_token = access_token['oauth_token']
    profile.oauth_secret = access_token['oauth_token_secret']
    profile.save()

    # Authenticate the user and log them in using Django's pre-built
    # functions for these things.
    user = authenticate(username=access_token['screen_name'],
            password=access_token['oauth_token_secret'])
    print user
    login(request, user)

    #context = {}
    #return render(request, 'dashboard.html', context)
    return HttpResponseRedirect('/dashboard/landing')