Exemplo n.º 1
0
    def post(self, *args, **kwargs):
        result = {'status': True, 'data': '', 'error': ''}  # 返回值格式
        login_name = self.get_argument('login_name')
        login_pwd = self.get_argument('login_pwd')

        obj = forms.LoginForm()
        is_valid, success_dict, error_msg = obj.check_valid(self)

        if is_valid:
            conn = orm.session()
            # 查询出,code与email对应的数据
            # session.query(User).filter(and_(User.name.like("user%"), User.fullname.like("first%"))).all()
            ret = conn.query(orm.UserInfo).filter(
                and_(orm.UserInfo.username == login_name,
                     orm.UserInfo.password == login_pwd)).first()
            # 如果用户存在
            if ret:
                # 将session信息写入cookies中
                self.session['is_login'] = True
                self.session['reg_name'] = ret.username
                self.session['email'] = ret.email
            else:
                result['status'] = False
                result['error'] = "用户不存在,或者密码有误!"
            self.write(json.dumps(result))
        else:
            self.render('error.html', error_msg=error_msg)
Exemplo n.º 2
0
def main():
    # 获取新闻数据
    conn = orm.session()
    news_list = conn.query(orm.News, orm.UserInfo).filter(
        and_(orm.News.user_info_id == orm.UserInfo.nid, orm.News.news_type_id==1)
    ).all()

    for item in news_list:
        print(item[0].title, item[1].username)
Exemplo n.º 3
0
    def post(self, *args, **kwargs):
        result = {'status': True, 'data': '', 'error': ''}  # 返回值格式

        user_email = self.get_argument('email')

        if user_email:

            sc = orm.Sendcode()
            sc.email = user_email
            sc.code = commons.random_code()
            sc.start_time = datetime.datetime.now()  # 获取当前时间.

            conn = orm.session()
            conn.add(sc)  # 添加到数据库
            conn.commit()  # 提交 commit一旦执行,sc对象中就没有数据了。
            print(sc.code)
            conn.close()
        else:
            result['error'] = '邮箱为空!'
            result['status'] = False

        self.write(json.dumps(result))  # 返回json数据
Exemplo n.º 4
0
    def get(self, *args, **kwargs):

        # try:
        #     news_type = self.get_argument('newstype')
        # except Exception as ex:
        #     news_type = 0
        #     print(ex)

        userinfo = {}

        conn = orm.session()

        news_list = conn.query(orm.News, orm.UserInfo).filter(
            orm.News.user_info_id == orm.UserInfo.nid).all()

        # if news_type:
        #     news_list = conn.query(orm.News, orm.UserInfo).filter(
        #         and_(orm.News.user_info_id == orm.UserInfo.nid, orm.News.news_type_id == news_type)
        #     ).all()
        # else:
        #     news_list = conn.query(orm.News, orm.UserInfo).filter(
        #         orm.News.user_info_id == orm.UserInfo.nid
        #     ).all()

        # print(json.loads(ret))
        if self.session['is_login']:
            userinfo['is_login'] = self.session['is_login']
            userinfo['reg_name'] = self.session['reg_name']
            userinfo['email'] = self.session['email']
            self.render('index.html',
                        error_msg=None,
                        userinfo=userinfo,
                        news=news_list)
        else:
            self.render('index.html',
                        error_msg=None,
                        userinfo=None,
                        news=news_list)
Exemplo n.º 5
0
    def post(self, *args, **kwargs):
        result = {'status': True, 'data': '', 'error': ''}  # 返回值格式
        checkcode = self.get_argument('checkcode')
        email = self.get_argument('email')
        obj = forms.RegForm()
        is_valid, success_dict, error_msg = obj.check_valid(self)

        # 如果表单验证通过
        if is_valid:
            conn = orm.session()
            # 查询出,code与email对应的数据
            # session.query(User).filter(and_(User.name.like("user%"), User.fullname.like("first%"))).all()
            ret = conn.query(orm.Sendcode).filter(
                and_(orm.Sendcode.code == checkcode,
                     orm.Sendcode.email == email)).first()
            # 如果有数据则,添加用户到userinfo表.
            if ret:
                user = orm.UserInfo()
                user.username = self.get_argument('reg_name')
                user.email = self.get_argument('email')
                user.password = self.get_argument('reg_pwd')
                user.ctime = datetime.datetime.now()
                user.status = 1

                conn.add(user)
                conn.commit()  # 提交, commit一旦执行,user对象中就没有数据了。
                conn.close()

                # 将session信息写入cookies中
                self.session['is_login'] = True
                self.session['reg_name'] = self.get_argument('reg_name')
                self.session['email'] = self.get_argument('email')
            else:
                result['status'] = False
                result['error'] = "验证码不正确!"
            self.write(json.dumps(result))
        else:
            self.render('error.html', error_msg=error_msg)