Example #1
0
    def post(self):
        user = g.current_user
        username = request.form.get('name', None)
        password = request.form.get('password', None)
        domain = request.form.get('domain', None)

        if username != user.name:
            status = check_username(username)
            if status:
                return render_template('account.setting.html', error=status[1])
            user.change_username(username)

        if domain and not user.domain:
            for status in [check_domain(domain), check_domain_exists(domain)]:
                if status:
                    return render_template('account.setting.html', error=status[1])
            user.set_domain(domain)

        if password:
            status = check_password(password)
            if status:
                return render_template('account.setting.html', error=status[1])
            user.change_password(password)
        #clear cache
        clear_user_cache(user)
        account_login(user)
        g.current_user = get_current_user()
        return render_template('account.setting.html', error=code.ACCOUNT_SETTING_SUCCESS)
Example #2
0
def get_user(username):
    try:
        username = int(username)
        if username <= 0:
            return None
        return User.query.get(username)
    except ValueError:
        if check_domain(username):
            return None
        return get_user_by_domain(domain=username)