예제 #1
0
    def edit_user(user_id):
        user = Journalist.query.get(user_id)

        if request.method == 'POST':
            if request.form.get('username', None):
                new_username = request.form['username']

                try:
                    Journalist.check_username_acceptable(new_username)
                except InvalidUsernameException as e:
                    flash('Invalid username: '******'error')
                    return redirect(url_for("admin.edit_user",
                                            user_id=user_id))

                if new_username == user.username:
                    pass
                elif Journalist.query.filter_by(
                        username=new_username).one_or_none():
                    flash(gettext(
                        'Username "{user}" already taken.').format(
                            user=new_username),
                        "error")
                    return redirect(url_for("admin.edit_user",
                                            user_id=user_id))
                else:
                    user.username = new_username

            user.is_admin = bool(request.form.get('is_admin'))

            commit_account_changes(user)

        password = make_password(config)
        return render_template("edit_account.html", user=user,
                               password=password)
예제 #2
0
def _get_username():
    while True:
        username = raw_input('Username: '******'Invalid username: ' + str(e))
        else:
            return username
예제 #3
0
def _get_username():
    while True:
        username = raw_input('Username: '******'Invalid username: ' + str(e))
        else:
            return username