示例#1
0
文件: urls.py 项目: saltdealer/space
def user_login():
    logging.info('user start to login')
    i = ctx.request.input(phone='',password='')
    phone = i.phone.strip()
    password = i.password.strip()
    logging.info('the passwd is %s' % password)
    if not phone or not _RE_PHONE.match(phone):
        raise APIError('Value:illegal','phone','The string is not a phone num','-1')
    if not password or not _RE_MD5.match(password):
        logging.info('the passwd is not illegal')
        raise APIError('Value:illegal','password','The password is not a md5string','-1')

    user = User.find_first('where phone=?', phone)
    image = Image.find_first('where id=?',user.image)
    user.image = image.image_path
    logging.info('the user is %s' % user.name)
    if user.password == password:
        user.errcode='0'
        user.pop('password')
        return user
    else:
        raise APIError('Authentication:fail','password','The password is not correct','-1')