예제 #1
0
def imaccount_edit(request, account_id=None):
    """Edit an existing game account or create a new one."""

    imaccount = None
    if account_id is not None:
        imaccount = IMAccount.query.get(account_id)
        if imaccount is None:
            raise NotFound()
        elif imaccount.user != request.user:
            raise Forbidden()
    form = EditIMAccountForm(request.user, imaccount)

    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('account/imaccount_list')
        elif request.form.get('delete') and imaccount:
            return redirect_to('account/imaccount_delete', account_id=account_id)
        elif form.validate(request.form):
            if imaccount is None:
                imaccount = form.make_imaccount()
                msg = _('IM account %s was added successfully.')
                icon = 'add'
            else:
                form.save_changes()
                msg = _('IM account %s was updated successfully.')
                icon = 'info'
            flash(msg % (escape(imaccount.account)), icon)

            db.commit()
            if 'save_and_continue' in request.form:
                return redirect_to('account/imaccount_edit', account_id=imaccount.id)
            return form.redirect('account/imaccount_list')
    return render_account_response('account/imaccount_edit.html', 'imaccounts',
                                    form=form.as_widget())
예제 #2
0
def profile(request):
    form = EditProfileForm(request.user)
    if request.method == 'POST':
        if 'cancel' in request.form:
            return form.redirect('account/index')
        elif 'delete' in request.form:
            return redirect_to('account/delete')
        elif form.validate(request.form):
            picfile = request.files.get('picfile')
            picture = UserPicture(request.user)
            if picfile:
                form.save_changes()
                picture.place_file(picfile)
            else:
                pictype = request.user.userpictype
                if not form['userpictype']:
                    form.data['userpictype'] = pictype
                if form['userpictype'] != pictype:
                   picture.remove()
                form.save_changes()
            db.commit()
            flash(_(u'Your profile was updated successfully.'), 'info')
            return form.redirect('account/index')
    return render_account_response('account/edit_profile.html', 'profile.profile',
                                   form=form.as_widget())
예제 #3
0
def change_password(request):
    """Allow the current user to change his password."""
    form = ChangePasswordForm(request.user)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('account/index')
        if form.validate(request.form):
            form.set_password()
            db.commit()
            flash(_(u'Password changed successfully.'), 'configure')
            return form.redirect('account/index')

    return render_account_response('account/change_password.html','profile.password',
        form=form.as_widget()
    )
예제 #4
0
def notification_settings(request):
    """Allow the user to change his notification settings."""
    form = make_notification_form(request.user)
    if request.method == 'POST' and form.validate(request.form):
        form.apply()
        db.commit()
        flash(_('Notification settings changed.'), 'configure')
        return form.redirect('account/notification_settings')

    return render_account_response('account/notification_settings.html', 'notifications',
        form=form.as_widget(),
        systems=sorted(request.app.notification_manager.systems.values(),
                       key=lambda x: x.name.lower()),
        notification_types=sorted(
            request.app.notification_manager.types(request.user),
            key=lambda x: x.description.lower()
        )
    )
예제 #5
0
def imaccount_delete(request, account_id):
    """Delete an InGame Account from user-account panel"""

    imaccount = IMAccount.query.get(account_id)
    if imaccount is None:
        raise NotFound()
    if imaccount.user != request.user:
        raise Forbidden()
    form = DeleteIMAccountForm(imaccount)

    if request.method == 'POST':
        if request.form.get('cancel'):
            return form.redirect('account/imaccount_list')
        elif request.form.get('confirm') and form.validate(request.form):
            accountname = str(imaccount.account)
            form.delete_account()
            db.commit()
            flash(_('IM account %s was deleted successfully') % accountname, 'remove')
            return redirect_to('account/imaccount_list')

    return render_account_response('account/imaccount_delete.html', 'imaccounts',
                                   form=form.as_widget())