示例#1
0
def create_user(request):
    """
    ./register POST
    username: 用户名
    password: 密码
    email: 邮箱
    """
    username = request.POST['username']
    email = request.POST['email']
    password = request.POST['password']

    user = User.objects.create_user(username, email, password)
    profile = Profile(user=user)
    profile.save()
    return HttpResponse("创建新用户成功")
示例#2
0
def user_register(request):
    context = {}
    if request.method == 'GET':
        context['form'] = RegisterForm()
        return render(request, 'game/register.html', context)

    form = RegisterForm(request.POST)

    if not form.is_valid():
        context['form'] = form
        return render(request, 'game/register.html', context)

    new_user = User.objects.create_user(username=form.cleaned_data['username'],
                                        password=form.cleaned_data['password'],
                                        email=form.cleaned_data['email'],
                                        first_name=form.cleaned_data['first_name'],
                                        last_name=form.cleaned_data['last_name'])
    new_user.save()
    default_profile = Profile(user=new_user)
    default_profile.gender = form.cleaned_data['gender']
    default_profile.save()
    login(request, new_user)
    return redirect(reverse('home'))
示例#3
0
文件: views.py 项目: 12romis/game
def signup(request):
    form = SignUpForm(request.POST)
    if form.is_valid():
        form.cleaned_data['username'] = form.cleaned_data.get('email')
        user = User.objects.create(**form.cleaned_data)
        user.set_password(form.cleaned_data.get('password'))
        user.profile = Profile()
        user.profile.token = get_random_string(length=32)
        user.profile.save()
        user.save()
        dic = {
            'token': user.profile.token,
            'email': user.email,
        }
        return JsonResponse(dic, content_type="application/json", safe=False)
    else:
        return JsonResponse({'errors': form.errors},
                            content_type="application/json",
                            status=400,
                            safe=False)
示例#4
0
def get_leaderboard(request):
    leader_dict = Profile.get_leaderboard(10,Profile.objects.get(user__id = request.user.id))
    return json_response(leader_dict)
示例#5
0
def get_score(request):
    player = Profile.objects.get(user__username=request.user.username)
    score = Profile.get_score(player)
    return json_response(score)
示例#6
0
def login(request):
    
    glo = GlobalValues.objects.get()
    #OYE!! LOOK OVER HERE!!!!! SREEJITH!!
    #Use glo in registration, you need to check these:
    # If session is inactive, don't allow people to login.
    # If allowReg (a new variable) is false, dont allow registrations either.
    
    # The workflow is: we get the `code` from the get request.
    # We then proceed to exchange it for an `access token` from facebook
    # We then obtain user info using the `access token` and proceed to
    # either log him in or sign him up.
    if request.user.is_authenticated():
        return redirect('game')
    if not glo.running and not glo.allowReg:
        return redirect('index_m', message = 'Sorry, no logging in or signing up currently.')
    
    fb_code = request.GET.get('code')
    try:
        if fb_code is not None:
            r = urlopen(Request('https://graph.facebook.com/oauth/access_token?client_id=414682281965382&redirect_uri=%s&client_secret=aa6b5e6eb4399581d7fc00e0cbc3eb93&code=%s'%(settings.REDIRECT_LOGIN_URI,fb_code)))
            token_response = r.read()
	    token_response = token_response.split('&')[0]
            user_data = json.load(urlopen(Request('https://graph.facebook.com/me?scope=email&%s'%token_response)))
            
            if 'error' in user_data:
                raise Exception("Error in retrieving data")
            
            try:
                profile = Profile.objects.get(facebook_id = user_data['id'])
            except Exception:
                if not glo.allowReg:
                    return redirect('index_m', message = 'New Registrations not allowed currently.')
                print user_data
                user = User.objects.create_user( user_data.get('username') or ( user_data.get('first_name') + user_data.get('last_name') + user_data.get('id') ),user_data.get('email') or "*****@*****.**",'sreejithhere')
                
                user.first_name = user_data.get('first_name')
                user.last_name = user_data.get('last_name')
                user.save()
                profile = Profile(user = user,
                                  facebook_id = user_data.get('id') or 0)
                profile.save()
                user_login = authenticate(username = user.username,
                                          password = '******')
                auth_login(request, user_login)
                if not glo.running:
                    return redirect('index_m', message = 'Thanks for registering. Login not allowed till next session starts.')
                return redirect('game')
            else:
                if not glo.running:
                    return redirect('index_m', message = 'Login not allowed till next session starts.')
                if profile.user.is_active:
                    user_login = authenticate(username = profile.user.username, password = '******')
                    auth_login(request, user_login)
                    return redirect('game')
                else:
                    return redirect('index_m', message = 'Your account has been deactivated.')
    except Exception as e:
        raise e
	return redirect('index_m',message = 'Exception thrown.')
    return redirect('index')
示例#7
0
from django.contrib.auth.models import User
from game.models import Profile

#for i in range(ord('a'), ord('z') + 1):
for j in range(ord('a'), ord('z') + 1):
    st = chr(j)
    email = st + '@' + st + '.' + st
    usr = User.objects.create_user(st, email, st)
    prof = Profile(user=usr, facebook_id=1)
    prof.save()