Exemple #1
0
 def post(self):
     form = RegisterForm()
     if form.validate_on_submit():
         email = form.email.data
         username = form.username.data
         password = form.password.data
         if User.query.filter_by(email=email).exists():
             msg = _('The email has been registered')
             return HTTPResponse(HTTPResponse.HTTP_CODE_PARA_ERROR,
                                 message=msg).to_response()
         if User.query.filter_by(username=username).exists():
             msg = _('The username has been registered')
             return HTTPResponse(HTTPResponse.HTTP_CODE_PARA_ERROR,
                                 message=msg).to_response()
         user = User(username=username, email=email)
         user.set_password(password)
         user.save()
         login(user, True)
         self.register_email(user)
         flash(_('An email has been sent to your.Please receive'))
         return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
     else:
         if form.errors:
             return return_errors(form)
         return render_template('auth/register.html', form=form)
Exemple #2
0
 def post(self):
     if current_user.is_confirmed:
         return HTTPResponse(HTTPResponse.USER_IS_CONFIRMED).to_response()
     self.send_email(current_user)
     return HTTPResponse(
         HTTPResponse.NORMAL_STATUS,
         description=_('An email has been sent to your.Please receive'
                       )).to_response()
Exemple #3
0
 def delete(self, replyId):
     user = request.user
     reply = Reply.query.filter_by(id=replyId).first_or_404()
     reply.likers.remove(user)
     reply.save()
     serializer = Serializer(reply, many=False)
     return HTTPResponse(
         HTTPResponse.NORMAL_STATUS, data=serializer.data).to_response()
Exemple #4
0
 def put(self, replyId):
     post_data = request.data
     reply = Reply.query.filter_by(id=replyId).first_or_404()
     content = post_data.pop('content', None)
     if content is not None:
         reply.content = content
     reply.save()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
Exemple #5
0
 def post(self):
     form = LoginForm()
     if form.validate_on_submit():
         username = form.username.data
         password = form.password.data
         remember = True if request.json.get('remember') else False
         user = User.query.filter_by(username=username).first()
         if user and user.check_password(password):
             login(user, remember)
             return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
         msg = _('Username or Password Error')
         return HTTPResponse(HTTPResponse.HTTP_CODE_PARA_ERROR,
                             message=msg).to_response()
     else:
         if form.errors:
             return return_errors(form)
         return render_template('auth/login.html', form=form)
Exemple #6
0
 def post(self, replyId):
     user = request.user
     reply = Reply.query.filter_by(id=replyId).first_or_404()
     reply.likers.append(user)
     reply.save()
     MessageClient.like(reply)
     serializer = Serializer(reply, many=False)
     return HTTPResponse(
         HTTPResponse.NORMAL_STATUS, data=serializer.data).to_response()
Exemple #7
0
 def post(self):
     form = ForgetForm()
     if form.validate_on_submit():
         email = form.email.data
         user = User.query.filter_by(email=email).first()
         if not user:
             msg = _('The email is error')
             return HTTPResponse(HTTPResponse.HTTP_CODE_PARA_ERROR,
                                 message=msg).to_response()
         password = ''.join(sample(ascii_letters + digits, 8))
         user.set_password(password)
         user.save()
         self.send_email(user, password)
         flash(
             _('An email has been sent to you.'
               'Please receive and update your password in time'))
         return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
     else:
         if form.errors:
             return return_errors(form)
         return render_template('auth/forget.html', form=form)
Exemple #8
0
 def put(self, pk):
     post_data = request.data
     collect = Collect.query.filter_by(id=pk).first_or_404()
     name = post_data.pop('name', None)
     description = post_data.pop('description', None)
     is_hidden = post_data.pop('is_hidden', None)
     if name is not None:
         collect.name = name
     if description is not None:
         collect.description = description
     if is_hidden is not None:
         collect.is_hidden = is_hidden
     collect.save()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
Exemple #9
0
 def put(self, topicId):
     form = form_board()
     post_data = form.data
     topic = Topic.query.filter_by(id=topicId).first_or_404()
     title = post_data.pop('title', None)
     content = post_data.pop('content', None)
     content_type = post_data.pop('content_type', None)
     category = post_data.pop('category', None)
     if title is not None:
         topic.title = title
     if content is not None:
         topic.content = content
     if content_type is not None:
         topic.content_type = content_type
     if category is not None:
         topic.board_id = int(category)
     topic.save()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
Exemple #10
0
 def wrapper(*args, **kwargs):
     form = form_class()
     if form.validate_on_submit():
         return func(*args, **kwargs)
     elif form.errors:
         if f is not None:
             if callable(f):
                 flash(f())
             elif f == '':
                 flash_errors(form)
             else:
                 flash(f)
         if error is not None:
             return error()
         return return_errors(form)
     if success is not None:
         return success()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
Exemple #11
0
 def delete(self, pk):
     collect = Collect.query.filter_by(id=pk).first_or_404
     collect.delete()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
Exemple #12
0
 def delete(self, replyId):
     reply = Reply.query.filter_by(id=replyId).first_or_404()
     reply.delete()
     return HTTPResponse(HTTPResponse.NORMAL_STATUS).to_response()
Exemple #13
0
def return_errors(form):
    for field, errors in form.errors.items():
        data = (u"%s %s" % (getattr(form, field).label.text, errors[0]))
        break
    return HTTPResponse(HTTPResponse.FORM_VALIDATE_ERROR,
                        description=data).to_response()