Esempio n. 1
0
    def post(self):
        args = strip(self.req.parse_args(), 'password')
        self.validate(args)

        query = or_(
            Account.username == args['account'],
            Account.email == args['account'],
        )
        user = Account.query.filter(query).first()
        if user is not None:
            if user.password != args['password']:
                abort(PASSWORD_ERROR)
            else:
                default = current_app.config.get('DEFAULT_AVATAR')
                profile = Profile.query.get(user.id)
                avatar = profile.avatar if profile and profile.avatar else default
                return dict(
                    user=dict(uid=user.id,
                              username=user.username,
                              avatar=avatar2url(avatar)),
                    token=create_token(3001, user.id, user.password.hash,
                                       time.time()),
                )
        else:
            abort(ACCOUNT_NOT_EXISTS)
Esempio n. 2
0
    def post(self, id):
        current_user.access_user()
        args = self.req.parse_args()
        args = strip(args)
        if not args['content']:
            abort(INVALID_ARGS)

        row = dict(content=args['content'],
                   uid=current_user.uid,
                   pubtime=time.time())
        total = mongo.comment.add(id, row)

        cache.delete_memoized(get_comments, id, (total + 9) / 10)

        profiles = current_user.accounts.profiles(current_user.uid)
        if profiles is None:
            return abort(INVALID_ARGS)

        profiles = dict(
            (int(x), y) for x, y in profiles['profiles'].iteritems())
        comment = {
            'nickname': profiles[row['uid']]['nickname'],
            'avatar': profiles[row['uid']]['avatar'],
            'content': row['content'],
            'pubdate': time2best(row['pubtime']),
            'num': total + 1,
        }
        return dict(comment=comment)
Esempio n. 3
0
	def post(self):
		args = strip(self.req.parse_args(), 'password')
		self.validate(args)

		query = or_(
			Account.username == args['account'], 
			Account.email == args['account'],
		)
		user = Account.query.filter(query).first()
		if user is not None:
			if user.password != args['password']:
				abort(PASSWORD_ERROR)
			else:
				default = current_app.config.get('DEFAULT_AVATAR')
				profile = Profile.query.get(user.id)
				avatar = profile.avatar if profile and profile.avatar else default
				return dict(
					user=dict(uid=user.id, username=user.username, avatar=avatar2url(avatar)),
					token=create_token(3001, user.id, user.password.hash, time.time()),
				)
		else:
			abort(ACCOUNT_NOT_EXISTS)
Esempio n. 4
0
 def post(self):
     args = strip(self.req.parse_args(), 'password')
     self.validate(args)
     if hasattr(self, 'from_%s' % args['type']):
         return getattr(self, 'from_%s' % args['type'])(args)
     abort(INVALID_ARGS)
Esempio n. 5
0
 def post(self):
     current_user.access_user()
     args = strip(self.req.parse_args())
     self.validate(args)
     self.save(args)
     return {}
Esempio n. 6
0
 def post(self):
     current_user.access_user()
     args = strip(self.req.parse_args())
     save_profile(args)
     return {'avatar': avatar2url(args['avatar'])}
Esempio n. 7
0
	def post(self):
		args = strip(self.req.parse_args(), 'password')
		self.validate(args)
		if hasattr(self, 'from_%s' % args['type']):
			return getattr(self, 'from_%s' % args['type'])(args)
		abort(INVALID_ARGS)