Beispiel #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)
Beispiel #2
0
 def post(self):
     user = g.current_user
     upload_avatar = request.files['file']
     if not upload_avatar:
         return render_template('account.avatar.html', path = user.avatar, error = 'Please select avatar file')
     uploader = get_uploader()
     filename, stream, error = process_file(user, upload_avatar)
     if error:
         return render_template('account.avatar.html', path = user.avatar, error = error)
     uploader.writeFile(filename, stream)
     purge(filename)
     user.set_avatar(filename)
     clear_user_cache(user)
     return redirect(url_for('account.avatar', ok = 1))
Beispiel #3
0
    def get(self, stub):
        forget = get_forget_by_stub(stub=stub)
        if g.current_user:
            if forget:
                forget.delete()
            return redirect(url_for('index'))

        if not forget:
            raise abort(404)

        if (datetime.now()  - forget.created).seconds > config.FORGET_STUB_EXPIRE:
            forget.delete()
            return render_template('account.reset.html', hidden=1, \
                    error=code.ACCOUNT_FORGET_STUB_EXPIRED)
        return render_template('account.reset.html', stub=stub)
Beispiel #4
0
 def get(self, uid):
     if uid == g.current_user.id:
         return redirect(url_for('topic.index'))
     who = get_user(uid)
     if not who:
         raise abort(404)
     title = request.args.get('title', '')
     return render_template('topic.create.html', uid=uid, who=who, title=title)
Beispiel #5
0
 def post(self):
     if request.form and 'cancel' in request.form:
         return redirect(url_for('index'))
     email = request.form.get('email', None)
     status = check_email(email)
     if status:
         return render_template('account.forget.html', error=status[1])
     user = get_user_by_email(email=email)
     if user:
         stub = create_token(20)
         try:
             send_email(user.email, \
                 config.FORGET_EMAIL_TITLE,
                 origin_render('email.html', user=user, stub=stub))
         except:
             logger.exception("send mail failed")
         create_forget(user.id, stub)
     return render_template('account.forget.html', send=1)
Beispiel #6
0
    def post(self):
        login_url = url_for('account.login', **request.args)
        password = request.form.get('password', None)
        email = request.form.get('email', None)
        check, error = check_login_info(email, password)
        if not check:
            return render_template('account.login.html', login_info=error, login_url=login_url)

        user = get_user_by(email=email).limit(1).first()
        if not user:
            logger.info('no such user')
            return render_template('account.login.html', login_info='no such user', login_url=login_url)
        if not user.check_password(password):
            logger.info('invaild passwd')
            return render_template('account.login.html', login_info='invaild passwd', login_url=login_url)

        account_login(user)
        redirect_url = request.args.get('redirect', None)
        return redirect(redirect_url or url_for('index'))
Beispiel #7
0
    def post(self, stub):
        forget = get_forget_by_stub(stub=stub)
        if g.current_user:
            if forget:
                forget.delete()
            return redirect(url_for('index'))

        if not forget:
            raise abort(404)

        password = request.form.get('password', None)
        status = check_password(password)
        if status:
            return render_template('account.reset.html', stub=stub, \
                    error=status[1])
        user = get_user(forget.uid)
        user.change_password(password)
        account_login(user)
        forget.delete()
        clear_user_cache(user)
        backend.delete('account:%s' % forget.stub)
        return render_template('account.reset.html', ok=1)
Beispiel #8
0
 def get(self):
     page = request.args.get('p', '1')
     if not page.isdigit():
         raise abort(404)
     page = int(page)
     msg = request.args.get('msg', None)
     list_page = get_user_topics(g.current_user.id, page)
     if page >1:
         page_1 = get_user_topics(g.current_user.id, 1)
         if list_page.total != page_1 or list_page.last_time != page_1.last_time:
             backend.delete('topic:list:%d:%d' % (g.current_user.id, page))
             list_page = get_user_topics(g.current_user.id, page)
     return render_template('topic.index.html', msg=msg, \
             topics=format_topic_list(list_page.items), list_page=list_page)
Beispiel #9
0
 def post(self):
     username = request.form.get('name', None)
     password = request.form.get('password', None)
     email = request.form.get('email', None)
     check, error = check_register_info(username, email, password)
     if not check:
         return render_template('account.register.html', error=error)
     oauth = session.pop('from_oauth', None)
     user = create_user(username, password, email)
     #clear cache
     clear_user_cache(user)
     account_login(user)
     if oauth:
         oauth.bind(user.id)
     return redirect(url_for('index'))
Beispiel #10
0
 def post(self, uid):
     if uid == g.current_user.id:
         return redirect(url_for('topic.index'))
     who = get_user(uid)
     to_uid = request.form.get('to_uid')
     title = request.form.get('title')
     content = request.form.get('content')
     if not who:
         #TODO return error code
         # check other params
         return render_template('topic.create.html', uid=uid)
     topic = make_topic(g.current_user.id, to_uid, title, content)
     #clean cache
     clean_cache(g.current_user.id, uid, topic.id)
     return redirect(url_for('topic.index'))
Beispiel #11
0
 def get(self, tid):
     page = request.args.get('p', '1')
     topic = get_topic(tid)
     if not topic or not page.isdigit():
         raise abort(404)
     page = int(page)
     if mark_read(g.current_user.id, tid):
         backend.delete('topic:user_topic:%d:%d' % (g.current_user.id, tid))
         backend.delete('topic:notify:%d' % g.current_user.id)
         backend.delete('topic:list:%d:1' % g.current_user.id)
     list_page = get_user_replies(tid, page)
     if page > 1 and list_page.total != get_user_replies(tid, 1):
         backend.delete('topic:replies:%d:%d' % (tid, page))
         list_page = get_user_replies(tid, page)
     #TODO check reply count!!!
     return render_template('topic.view.html', \
             replies=format_reply_list(list_page.items), \
             topic=topic, list_page=list_page)
Beispiel #12
0
 def get(self):
     user = g.current_user
     key = None
     if not user.weixin:
         key = make_token(user.id)
     return render_template('account.weixin.html', key = key)
Beispiel #13
0
 def get(self):
     return render_template('account.bind.html')
Beispiel #14
0
def index():
    return render_template('index.html')
Beispiel #15
0
 def get(self):
     return render_template('account.setting.html')
Beispiel #16
0
 def get(self):
     login_url = url_for('account.login', **request.args)
     return render_template('account.login.html', login_url=login_url)
Beispiel #17
0
 def get(self):
     user = g.current_user
     ok = request.args.get('ok', None)
     return render_template('account.avatar.html', path = user.avatar, ok = ok, \
             salt = time.time())
Beispiel #18
0
 def get(self):
     if request.form and 'cancel' in request.form:
         return redirect(url_for('index'))
     return render_template('account.forget.html')
Beispiel #19
0
 def get(self, username):
     visit_user = get_user(username)
     if not visit_user:
         raise abort(404)
     return render_template('account.people.html', \
             visit_user = visit_user)
Beispiel #20
0
 def get(self):
     return render_template('account.register.html')