def register(): if is_login(): return redirect(url_for('home.index')) if request.method == 'GET': return render('account/register.html') f = request.form model = db.User() model['email'] = f.get('email') exist = db.User.find({'email': model['email']}).count() > 0 if exist: return render_json(u'那个,邮箱%s已经存在...' % model['email']) model['create_time'] = cn_time_now() model['nickname'] = f.get('nickname') model['password'] = db.User.encode_pwd(f.get('password')) if not user.check_invitation(f.get('invitation')): return render_json(u'邀请码不正确或者已被使用') try: model.save() user.login(model['email'], model['password']) user.remove_invitation(f.get('invitation')) return render_success() except Exception, e: app.logger.error(e) return render_json(unicode(e))
def register(): if is_login(): return redirect(url_for('home.index')) if request.method == 'GET': return render('account/register.html') f = request.form model = db.User() model['email'] = f.get('email') exist = db.User.find({ 'email': model['email'] }).count() > 0 if exist: return render_json(u'那个,邮箱%s已经存在...' % model['email']) model['create_time'] = cn_time_now() model['nickname'] = f.get('nickname') model['password'] = db.User.encode_pwd(f.get('password')) if not user.check_invitation(f.get('invitation')): return render_json(u'邀请码不正确或者已被使用') try: model.save() user.login(model['email'], model['password']) user.remove_invitation(f.get('invitation')) return render_success() except Exception, e: app.logger.error(e) return render_json(unicode(e))
def login(self, email, password, encode_pwd=False): if encode_pwd: password = self.encode_pwd(password) model = self.find_one({"email": email, "password": password}) if model: model["login_ip"] = unicode(request.remote_addr) model["login_time"] = cn_time_now() model.save() return model
def login(self, email, password, encode_pwd=False): if encode_pwd: password = self.encode_pwd(password) model = self.find_one({ 'email': email, 'password': password }) if model: model['login_ip'] = unicode(request.remote_addr) model['login_time'] = cn_time_now() model.save() return model
def finish(): try: id = ObjectId(request.form.get('id')) pss = request.form.get('pass') == 'true' u = user.get_user() model = db.Word.find_one({ '_id':id, 'user_id': u.id }) if not model: return render_json('') if pss: model.delete() else: model['add_time'] = cn_time_now() model.save() return render_success() except Exception, e: abort(404)
def get_words(): u = user.get_user() dt = cn_time_now() - datetime.timedelta(hours=config.BURY_HOURS) models = db.Word.find({'user_id': u.id, 'add_time': {'$lt': dt}}) total = models.count() data = [] keys = ['word', 'sound', 'phon', 'pos', 'sent', 'def', 'note'] for m in models.limit(config.PAGE_SIZE): w = {'id': str(m['_id']), 'add_time': format_datetime(m['add_time'])} for k in keys: w[k] = m[k] data.append(w) context = { 'status': 1, 'data': data, 'total': total, 'over': total <= config.PAGE_SIZE } return jsonify(context)
def add(): if request.method == 'GET': return render('word/add.html') f = request.form model = db.Word() model['word'] = f.get('word') model['sound'] = f.get('sound') model['phon'] = f.get('phon') model['pos'] = f.get('pos') model['sent'] = f.get('sent') model['def'] = f.get('def') model['note'] = f.get('note') model['user_id'] = user.get_user().id model['add_time'] = cn_time_now() try: model.save() return render_success() except Exception, e: app.logger.error(e) return render_json(e)
def get_words(): u = user.get_user() dt = cn_time_now() - datetime.timedelta(hours=config.BURY_HOURS) models = db.Word.find({ 'user_id': u.id, 'add_time': { '$lt': dt } }) total = models.count() data = [] keys = [ 'word', 'sound', 'phon', 'pos', 'sent', 'def', 'note' ] for m in models.limit(config.PAGE_SIZE): w = { 'id': str(m['_id']), 'add_time': format_datetime(m['add_time']) } for k in keys: w[k] = m[k] data.append(w) context = { 'status': 1, 'data': data, 'total': total, 'over': total <= config.PAGE_SIZE } return jsonify(context)