コード例 #1
0
ファイル: controller.py プロジェクト: Tyler-D/Zfile
    def password(self):
        """修改密码
        """
        # 字段信息验证
        password_form = form.Form(
                form.Password('password', self.vnotnullpassword),
                form.Password('new_password', self.vnotnullpassword,
                    self.vpassword),
                validators = [
                    self.vcmppassword,
                    ]
                )
        f = password_form()
        if not f.validates():
            self.resp = {'errno': errno_form, 'msg': f.get_note()}
            return self.json()

        params = self.req_params()
        password, new_password, repeat_password = params.password, params.new_password, params.repeat_password
        token = web.ctx.session.token
        userid = auth.decode_token(token)['userid']

        user_li = self.db.query_all("select id from user where id='%s' and password='******'" % (userid, auth.get_hashed_password(password,
                    user_passwd_salt)))
        if 0 == len(user_li):
            self.resp = {'errno': errno_db, 'msg': '密码出错'}
            return self.json()

        self.db.query("""update user set password='******' where id='%s'""" %
                (auth.get_hashed_password(new_password, user_passwd_salt), userid))
        self.db.commit()

        self.resp = {'errno': errno_ok, 'msg': '修改完成'}
        return self.json();
コード例 #2
0
ファイル: controller.py プロジェクト: Tyler-D/Zfile
    def reset(self):
        """重置密码
        """
        params = self.req_params()
        userid = params.id

        self.db.query("""update user set password='******' where id='%s'""" %
                (auth.get_hashed_password(default_passwd, user_passwd_salt),
                    userid))
        self.db.commit()
        self.resp = {'errno': errno_ok, 'msg': '重置完成'}
        return self.json()
コード例 #3
0
ファイル: controller.py プロジェクト: Tyler-D/Zfile
    def register(self):
        """注册
        """
        # 字段信息验证
        register_form = form.Form(
                form.Textbox('name', self.vnotnullname, self.vname),
                form.Textbox('email', self.vnotnullemail, self.vemail),
                form.Password('password', self.vnotnullpassword, self.vpassword),
                validators = [
                    self.vcmppassword,
                    ]
                )
        f = register_form()
        if not f.validates():
            self.resp = {'errno': errno_form, 'msg': f.get_note()}
            return self.json()

        params = self.req_params()
        name, email, password = params.name, params.email, params.password

        if not user_unique(self, name, email):
            return self.json()

        self.db.query("""insert into user (`name`, `email`, `password`, `create_time`, `last_login_time`) values('%s', '%s', '%s', '%s', '%s')""" % (name, email,
                    auth.get_hashed_password(password, user_passwd_salt),
                    timeutil.get_current_date(), timeutil.get_current_date()))
        user_li = self.db.query_all("""select id from user where name='%s'""" % (name))
        if 0 == len(user_li):
            self.resp = {'errno': errno_db, 'msg': '数据库操作失败'}
            return self.json()
        fs_path = user_li[0]['id'] + '/'
        print 'fs_path', fs_path
        self.db.query("""insert into quota (total, create_time, fs_path,
                user_id) values('%s', '%s', '%s', '%s')""" %
                (default_total_quota, timeutil.get_current_date(), fs_path,
                user_li[0]['id']))

        self.db.commit()

        self.resp = {'errno': errno_ok, 'msg': '注册完成'}
        return self.json()
コード例 #4
0
ファイル: controller.py プロジェクト: Tyler-D/Zfile
    def login_auth(self):
        """登录认证
        """
        params = self.req_params()
        # 字段信息验证
        login_auth_form = form.Form(
                form.Textbox('account', self.vnotnullaccount, self.vaccount),
                form.Password('password', self.vnotnullpassword, self.vpassword),
                )
        f = login_auth_form()
        if not f.validates():
            self.resp = {'errno': errno_form, 'msg': f.get_note()}
            return self.json()

        account, password = params.account, params.password
        user_li = self.db.query_all("select * from user where `name`='%s' and `password`='%s'" % (account, auth.get_hashed_password(password, user_passwd_salt)))
        self.db.commit()

        if 0 == len(user_li):
            user_li = self.db.query_all("select * from user where `email`='%s' and `password`='%s'" % (account, auth.get_hashed_password(password, user_passwd_salt)))
            self.db.commit()

        if 0 == len(user_li):
            self.resp = {'errno': errno_auth, 'msg': '用户名或密码错误'}
            return self.json()

        if int(user_li[0]['state']) == state_inactive:
            self.resp = {'errno': errno_auth, 'msg': '未激活'}
            return self.json()

        web.ctx.session.token = auth.create_token(user_li[0]['id'])
        self.resp = {'errno': errno_ok, 'msg': '登录完成'}
        return self.json()