コード例 #1
0
ファイル: views.py プロジェクト: Shavakan/otlplus
def login_callback(request):
    if request.method == "GET":
        next = request.session.pop('next', '/')
        tokenid = request.GET.get('tokenid', '')

        sso_profile = sso_client.get_user_info(tokenid)
        username = sso_profile['first_name'] + sso_profile['last_name'] 

        user_list = User.objects.filter(username=username)
        try:
            kaist_info = json.loads(sso_profile['kaist_info'])
            student_id = kaist_info.get('ku_std_no')
        except:
            student_id = ''
        if len(user_list) == 0:
            user = User.objects.create_user(username=username,
                        email=sso_profile['email'],
                        password=str(random.getrandbits(32)),
                        first_name=sso_profile['first_name'],
                        last_name=sso_profile['last_name'])
            user.save()
            user_profile = UserProfile(user=user, student_id=student_id)
            user_profile.sid = sso_profile['sid']
            user_profile.save()
            user = authenticate(username=username)
            login(request, user)
            return redirect(next)
        else:
           user = authenticate(username=user_list[0].username)
           user_profile = UserProfile.objects.get(user=user)
           user_profile.student_id = student_id
           login(request, user)
           return redirect(next)
    return render('/session/login.html', {'error': "Invalid login"})
コード例 #2
0
ファイル: views.py プロジェクト: sparcs-kaist/araplus
def user_register(request):
    if 'info' not in request.session:
        return redirect('/session/login/')

    info = request.session['info']
    if len(User.objects.filter(username=info['username'])) > 0:
        del request.session['info']
        return redirect('/session/login/')

    if request.method == 'POST':
        nickname = request.POST['nickname']
        password = request.POST['password']
        if validate_nickname(nickname):
            user = User.objects.create_user(username=info['username'],
                                            email=info['email'],
                                            password=password,
                                            first_name=info['first_name'],
                                            last_name=info['last_name'])

            user_profile = UserProfile(user=user,
                                       gender=info['gender'],
                                       birthday=info['birthday'],
                                       nickname=nickname)
        user_profile.save()

        return render(request, 'session/register_complete.html')
    return render(request, 'session/register.html', {'info': info})
コード例 #3
0
ファイル: views.py プロジェクト: Shavakan/araplus
def user_register(request):
    if 'info' not in request.session:
        return redirect('/session/login/')

    info = request.session['info']
    if len(User.objects.filter(username=info['username'])) > 0:
        del request.session['info']
        return redirect('/session/login/')

    if request.method == 'POST':
        nickname = request.POST['nickname']
        password = request.POST['password']
        if validate_nickname(nickname):
            user = User.objects.create_user(username=info['username'],
                                            email=info['email'],
                                            password=password,
                                            first_name=info['first_name'],
                                            last_name=info['last_name'])

            user_profile = UserProfile(user=user,
                                       gender=info['gender'],
                                       birthday=info['birthday'],
                                       nickname=nickname)
        user_profile.save()

        return render(request, 'session/register_complete.html')
    return render(request, 'session/register.html', {'info': info})
コード例 #4
0
ファイル: views.py プロジェクト: juheeuu/otlplus
def login_callback(request):
    next = request.session.pop('next', '/')
    state_before = request.session.get('sso_state', 'default before state')
    state = request.GET.get('state', 'default state')

    if state_before != state:
        return render(request, 'session/login_error.html', {
            'error_title': "Login Error",
            'error_message': "Invalid login"
        })

    code = request.GET.get('code')
    sso_profile = sso_client.get_user_info(code)
    username = sso_profile['sid']

    user_list = User.objects.filter(username=username)
    try:
        kaist_info = json.loads(sso_profile['kaist_info'])
        student_id = kaist_info.get('ku_std_no')
    except:
        student_id = ''

    if student_id is None:
        student_id = ''

    if len(user_list) == 0:
        user = User.objects.create_user(username=username,
                                        email=sso_profile['email'],
                                        password=str(random.getrandbits(32)),
                                        first_name=sso_profile['first_name'],
                                        last_name=sso_profile['last_name'])
        user.save()

        try:
            user_profile = UserProfile.objects.get(
                student_id=sso_profile['sid'])
            user_profile.user = user
        except:
            user_profile = UserProfile(student_id=student_id, user=user)

        user_profile.sid = sso_profile['sid']
        user_profile.save()

        if not settings.DEBUG:
            os.chdir('/var/www/otlplus/')
        os.system('python do_import_user_major.py %s' % student_id)
        os.system('python update_taken_lecture_user.py %s' % student_id)
        OldTimeTable.import_in_for_user(student_id)

        user = authenticate(username=username)
        login(request, user)
        return redirect(next)
    else:
        user = authenticate(username=user_list[0].username)
        user.first_name = sso_profile['first_name']
        user.last_name = sso_profile['last_name']
        user.save()
        user_profile = UserProfile.objects.get(user=user)
        previous_student_id = user_profile.student_id
        user_profile.student_id = student_id
        user_profile.save()
        if previous_student_id != student_id:
            if not settings.DEBUG:
                os.chdir('/var/www/otlplus/')
            os.system('python do_import_user_major.py %s' % student_id)
            os.system('python update_taken_lecture_user.py %s' % student_id)
            OldTimeTable.import_in_for_user(student_id)
        login(request, user)
        return redirect(next)
    return render(request, 'session/login_error.html', {
        'error_title': "Login Error",
        'error_message': "No such that user"
    })
コード例 #5
0
ファイル: views.py プロジェクト: ashe-sparcs/otlplus
def login_callback(request):
    next = request.session.pop('next', '/')
    state_before = request.session.get('sso_state', 'default before state')
    state = request.GET.get('state', 'default state')

    if state_before != state:
        return render(request, 'session/login_error.html',
                      {'error_title': "Login Error",
                       'error_message': "Invalid login"})

    code = request.GET.get('code')
    sso_profile = sso_client.get_user_info(code)
    username = sso_profile['sid']

    user_list = User.objects.filter(username=username)
    try:
        kaist_info = json.loads(sso_profile['kaist_info'])
        student_id = kaist_info.get('ku_std_no')
    except:
        student_id = ''

    if len(user_list) == 0:
        user = User.objects.create_user(username=username,
                    email=sso_profile['email'],
                    password=str(random.getrandbits(32)),
                    first_name=sso_profile['first_name'],
                    last_name=sso_profile['last_name'])
        user.save()

        try:
            user_profile = UserProfile.objects.get(student_id=sso_profile['sid'])
            user_profile.user = user
        except:
            user_profile = UserProfile(student_id=student_id, user = user)

        user_profile.sid = sso_profile['sid']
        user_profile.save()

        if not settings.DEBUG:
            os.chdir('/var/www/otlplus/')
        os.system('python update_taken_lecture_user.py %s' % student_id)

        user = authenticate(username=username)
        login(request, user)
        return redirect(next)
    else:
        user = authenticate(username=user_list[0].username)
        user.first_name=sso_profile['first_name']
        user.last_name=sso_profile['last_name']
        user.save()
        user_profile = UserProfile.objects.get(user=user)
        previous_student_id = user_profile.student_id
        user_profile.student_id = student_id
        user_profile.save()
        if previous_student_id != student_id:
            if not settings.DEBUG:
                os.chdir('/var/www/otlplus/')
            os.system('python update_taken_lecture_user.py %s' % student_id)
        login(request, user)
        return redirect(next)
    return render(request, 'session/login_error.html',
                  {'error_title': "Login Error",
                   'error_message': "No such that user"})
コード例 #6
0
def login_callback(request):
    next = request.session.pop('next', '/')
    state_before = request.session.get('sso_state', 'default before state')
    state = request.GET.get('state', 'default state')

    # if state_before != state:
    #     return render(request, 'session/login_error.html',
    #                   {'error_title': "Login Error",
    #                    'error_message': "Invalid login"})

    code = request.GET.get('code')
    # sso_profile = sso_client.get_user_info(code)
    sso_profile = {
        u'first_name': u'\uc7ac\uc601',
        u'last_name': u'\ud669',
        u'kaist_id': u'',
        u'uid': u'1ff7de1fd6272f8982fb',
        u'gender': u'*M',
        u'facebook_id': u'',
        u'twitter_id': u'',
        u'birthday': u'1997-11-24',
        u'flags': [u'TEST', u'SPARCS'],
        u'sid': u'43760d931fadde80aee2',
        u'kaist_info': u'',
        u'sparcs_id': u'akais',
        u'email': u'*****@*****.**',
        u'kaist_info_time': u''
    }
    username = sso_profile['sid']

    user_list = User.objects.filter(username=username)
    try:
        kaist_info = json.loads(sso_profile['kaist_info'])
        student_id = kaist_info.get('ku_std_no')
    except:
        student_id = ''

    if student_id is None:
        student_id = ''

    if len(user_list) == 0:
        user = User.objects.create_user(username=username,
                                        email=sso_profile['email'],
                                        password=str(random.getrandbits(32)),
                                        first_name=sso_profile['first_name'],
                                        last_name=sso_profile['last_name'])
        user.save()

        try:
            user_profile = UserProfile.objects.get(
                student_id=sso_profile['sid'])
            user_profile.user = user
        except:
            user_profile = UserProfile(student_id=student_id, user=user)

        user_profile.sid = sso_profile['sid']
        user_profile.save()

        if not settings.DEBUG:
            os.chdir('/var/www/otlplus/')
        os.system('python do_import_user_major.py %s' % student_id)
        os.system('python update_taken_lecture_user.py %s' % student_id)
        OldTimeTable.import_in_for_user(student_id)

        user = authenticate(username=username)
        login(request, user)
        return redirect(next)
    else:
        user = authenticate(username=user_list[0].username)
        user.first_name = sso_profile['first_name']
        user.last_name = sso_profile['last_name']
        user.save()
        user_profile = UserProfile.objects.get(user=user)
        previous_student_id = user_profile.student_id
        user_profile.student_id = student_id
        user_profile.save()
        if previous_student_id != student_id:
            if not settings.DEBUG:
                os.chdir('/var/www/otlplus/')
            os.system('python do_import_user_major.py %s' % student_id)
            os.system('python update_taken_lecture_user.py %s' % student_id)
            OldTimeTable.import_in_for_user(student_id)
        login(request, user)
        return redirect(next)
    return render(request, 'session/login_error.html', {
        'error_title': "Login Error",
        'error_message': "No such that user"
    })