コード例 #1
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def reset_password(request, id, code):
    form = ResetPassForm()
    error_message = ''
    player_activation = get_or_none(PlayerActivation, id=id, code=code)
    if player_activation is not None:
        expired_date = player_activation.created_date + timedelta(days=10)
        if datetime.now().date() > expired_date:
            error_message = _('Active code is expired !')
        else:
            if request.method == 'POST':
                form = ResetPassForm(request.POST)
                #Check if data is valid
                if form.is_valid():
                    new_password = form.cleaned_data['new_password']
                    player = player_activation.player
                    player.set_password(new_password)
                    player.is_active = True
                    player.save()
                    player_activation.delete()

                    return redirect('/')
    else:
        error_message = _('Active code not exist !')

    return render_to_response('home/reset_password.html', {'error_message': error_message, 'form': form},
                              context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def signin(request):
    #Check if user logging
    player = get_current_user(request)
    if player:
        return redirect(dashboard)

    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            player = get_or_none(Player, email=email)
            if player and player.check_password(password):
                if player.is_active:
                    request.session['player'] = player
                    set_lang(request, player.language_code)
                    return redirect(dashboard)
                else:
                    from django.forms.util import ErrorList

                    errors = form._errors.setdefault("email", ErrorList())
                    errors.append(_('Account is not active. Please check your email !'))
            else:
                from django.forms.util import ErrorList

                errors = form._errors.setdefault("email", ErrorList())
                errors.append(_('User or password incorrect'))
    else:
        form = None
    return index(request, form)
コード例 #3
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def signin(request):
    #Check if user logging
    player = get_current_user(request)
    if player:
        return redirect(dashboard)

    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            email = request.POST['email']
            password = request.POST['password']
            player = get_or_none(Player, email=email)
            if player and player.check_password(password):
                if player.is_active:
                    request.session['player'] = player
                    set_lang(request, player.language_code)
                    return redirect(dashboard)
                else:
                    from django.forms.util import ErrorList

                    errors = form._errors.setdefault("email", ErrorList())
                    errors.append(
                        _('Account is not active. Please check your email !'))
            else:
                from django.forms.util import ErrorList

                errors = form._errors.setdefault("email", ErrorList())
                errors.append(_('User or password incorrect'))
    else:
        form = None
    return index(request, form)
コード例 #4
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def reset_password(request, id, code):
    form = ResetPassForm()
    error_message = ''
    player_activation = get_or_none(PlayerActivation, id=id, code=code)
    if player_activation is not None:
        expired_date = player_activation.created_date + timedelta(days=10)
        if datetime.now().date() > expired_date:
            error_message = _('Active code is expired !')
        else:
            if request.method == 'POST':
                form = ResetPassForm(request.POST)
                #Check if data is valid
                if form.is_valid():
                    new_password = form.cleaned_data['new_password']
                    player = player_activation.player
                    player.set_password(new_password)
                    player.is_active = True
                    player.save()
                    player_activation.delete()

                    return redirect('/')
    else:
        error_message = _('Active code not exist !')

    return render_to_response('home/reset_password.html', {
        'error_message': error_message,
        'form': form
    },
                              context_instance=RequestContext(request))
コード例 #5
0
def login(request):
    """
    Login API
    """
    params = ['email', 'password']
    for par in params:
        if par not in request.POST:
            return Response(
                ReturnObject(2,
                             _('%s is required') % par, None).to_json())

    email = request.POST['email']
    password = request.POST['password']

    if email == '':
        return Response(
            ReturnObject(2, _('Email is not null'), None).to_json())

    if password == '':
        return Response(
            ReturnObject(2, _('Password is not null'), None).to_json())

    player = get_or_none(Player, email=email)
    if player and player.check_password(password):
        request.session['player'] = player
        request.session.save()
        return_object = ReturnObject(1, request.session.session_key,
                                     get_player_profile(request, player.id))
    else:
        return_object = ReturnObject(
            2, _('The email or password you entered is incorrect !'), None)
    return Response(return_object.to_json())
コード例 #6
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def login(request):
    """
    Login API
    """
    params = ['email', 'password']
    for par in params:
        if par not in request.POST:
            return Response(ReturnObject(2, _('%s is required') % par, None).to_json())

    email = request.POST['email']
    password = request.POST['password']

    if email == '':
        return Response(ReturnObject(2, _('Email is not null'), None).to_json())

    if password == '':
        return Response(ReturnObject(2, _('Password is not null'), None).to_json())

    player = get_or_none(Player, email=email)
    if player and player.check_password(password):
        request.session['player'] = player
        request.session.save()
        return_object = ReturnObject(1, request.session.session_key, get_player_profile(request, player.id))
    else:
        return_object = ReturnObject(2, _('The email or password you entered is incorrect !'), None)
    return Response(return_object.to_json())
コード例 #7
0
ファイル: forms.py プロジェクト: vongochung/mytutorial
    def clean_email(self):
        email = self.cleaned_data['email']
        player = get_or_none(Player, email=email)

        if player:
            return True
        else:
            raise forms.ValidationError(_('%s not exists') % email)
コード例 #8
0
ファイル: forms.py プロジェクト: vongochung/mytutorial
    def clean_email(self):
        email = self.cleaned_data['email']
        player = get_or_none(Player, email=email)

        if player:
            return True
        else:
            raise forms.ValidationError(_('%s not exists') % email)
コード例 #9
0
ファイル: forms.py プロジェクト: vongochung/mytutorial
    def clean_email(self):
        email = self.cleaned_data['email']
        player = get_or_none(Player, email=email)

        if player is not None:
            if player.fb_id == '' or player.fb_id is None:
                raise forms.ValidationError(_('%s was already existed') % email)
            else:
                raise forms.ValidationError(_('%s already exists via facebook') % email)
        else:
            return email
コード例 #10
0
ファイル: forms.py プロジェクト: vongochung/mytutorial
    def clean_email(self):
        email = self.cleaned_data['email']
        player = get_or_none(Player, email=email)

        if player is not None:
            if player.fb_id == '' or player.fb_id is None:
                raise forms.ValidationError(
                    _('%s was already existed') % email)
            else:
                raise forms.ValidationError(
                    _('%s already exists via facebook') % email)
        else:
            return email
コード例 #11
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def active_player(request, id, code):
    player_activation = get_or_none(PlayerActivation, id=id, code=code)
    is_expired = False
    success = False
    if player_activation is not None:
        expired_date = player_activation.created_date + timedelta(days=10)
        if datetime.now().date() > expired_date:
            is_expired = True
        else:
            player_activation.player.is_active = True
            player_activation.player.save()
            player_activation.delete()
            success = True

    data = {'player_activation': player_activation, 'is_expired': is_expired, 'success': success}
    return render_to_response('home/account_active.html', data, context_instance=RequestContext(request))
コード例 #12
0
ファイル: views.py プロジェクト: vongochung/mytutorial
def active_player(request, id, code):
    player_activation = get_or_none(PlayerActivation, id=id, code=code)
    is_expired = False
    success = False
    if player_activation is not None:
        expired_date = player_activation.created_date + timedelta(days=10)
        if datetime.now().date() > expired_date:
            is_expired = True
        else:
            player_activation.player.is_active = True
            player_activation.player.save()
            player_activation.delete()
            success = True

    data = {
        'player_activation': player_activation,
        'is_expired': is_expired,
        'success': success
    }
    return render_to_response('home/account_active.html',
                              data,
                              context_instance=RequestContext(request))
コード例 #13
0
def _render_user(facebook, request):
    me = facebook.get_myself()
    fb_id = me.id
    current_player = get_current_user(request)
    if current_player is not None:
        if fb_id != current_player.fb_id:
            #Check exit fb_id in table Player
            exit_fb_id = get_or_none(Player, fb_id=fb_id)
            if exit_fb_id is not None:
                if exit_fb_id.is_active:
                    del request.session['access_token']
                    return _('This facebook account is using by other player. Please try another!')
                else:
                    player = merge_users(current_player, exit_fb_id)
                    request.session['player'] = player
            else:
                player = get_or_none(Player, pk=current_player.id)
                player.fb_id = fb_id
                if hasattr(me, 'first_name'):
                    player.first_name = me.first_name
                if hasattr(me, 'last_name'):
                    player.last_name = me.last_name
                if hasattr(me, 'gender'):
                    if me.gender == 'male':
                        player.gender = 1
                    else:
                        player.gender = 0
                if hasattr(me, 'birthday'):
                    player.birth_date = datetime.strptime(me.birthday, "%m/%d/%Y").strftime("%Y-%m-%d")
                player.save()
                request.session['player'] = player
    else:
        player = get_or_none(Player, fb_id=fb_id)
        if player is None:
            set_username = False
            player = Player()

            #Check if account with email exist
            if hasattr(me, 'email'):
                email = me.email
                player = get_or_none(Player, email=email)
                if player is None:
                    player = Player()
                    player.email = email
                    player.username = email
                    set_username = True

            if hasattr(me, 'first_name'):
                player.first_name = me.first_name

            if hasattr(me, 'last_name'):
                player.last_name = me.last_name

            if hasattr(me, 'gender'):
                if me.gender == 'male':
                    player.gender = 1
                else:
                    player.gender = 0

            if hasattr(me, 'birthday'):
                player.birth_date = datetime.strptime(me.birthday, "%m/%d/%Y").strftime("%Y-%m-%d")

            if not set_username:
                player.username = fb_id

            player.fb_id = fb_id
            player.is_active = True
            player.save()
        else:
            if not player.is_active:
                #Merge account when account with email exist and account with facebook exist
                if hasattr(me, 'email'):
                    email = me.email
                    email_account = get_or_none(Player, ~Q(id=player.id), email=email)
                    if email_account is not None:
                        player = merge_users(email_account, player)
                    elif player.email is None or player.email == '':
                        player.email = email

                player.is_active = True
                player.save()

        request.session['player'] = player
    return ''