Beispiel #1
0
    def post(self):
        args = login_parser.parse_args()
        username = args['username']
        password = args['password']

        if not username or not password:
            raise UserOrPassIsNone()

        userobj = User.query.filter_by(username = username).first()

        if not userobj:
            return json_message(200, 'error', 'User is not exist')

        if not userobj.verify_password(password):
            return json_message(200, 'error', 'Password Error')

        userid = userobj.id

        data = dict(username=username,userid=userid)

        token = Token_Manager()
        token = token.generate_auth_token(data= data)


        session['token'] = token

        return json_message(200, 'message', 'Login Success')
Beispiel #2
0
    def post(self):
        args = login_parser.parse_args()
        username = args['username']
        password = args['password']

        if not username or not password:
            raise UserOrPassIsNone()

        userobj = User.query.filter_by(username=username).first()

        if not userobj:
            return json_message(200, 'error', 'User is not exist')

        if not userobj.verify_password(password):
            return json_message(200, 'error', 'Password Error')

        userid = userobj.id

        data = dict(username=username, userid=userid)

        token = Token_Manager()
        token = token.generate_auth_token(data=data)

        session['token'] = token

        return json_message(200, 'message', 'Login Success')
Beispiel #3
0
 def delete(self):
     '''
         Delete User's Domain name
     '''
     dname_id = request.args.get('dnameid')
     if dbdel(Dname,id=dname_id):
         return json_message('200', 'message', 'Delete Success')
     else:
         return json_message('200', 'error', 'Delete Failed')
Beispiel #4
0
 def delete(self):
     '''
         Delete Record
     '''
     record_id = request.args.get('record_id')
     obj = abort_if_id_doesnt_exist(Record, id=record_id)
     if obj:
         if dbdel(Record, id=record_id):
             return json_message('200', 'message', 'Delete Success')
         else:
             return json_message('200', 'error', 'Delete Failed')
     else:
         return json_message('200', 'error', 'Delete Failed')
Beispiel #5
0
 def delete(self):
     '''
         Delete Record
     '''
     record_id = request.args.get('record_id')
     obj = abort_if_id_doesnt_exist(Record,id=record_id)
     if obj:
         if dbdel(Record,id=record_id):
             return json_message('200', 'message', 'Delete Success')
         else:
             return json_message('200', 'error', 'Delete Failed')
     else:
         return json_message('200', 'error', 'Delete Failed')
Beispiel #6
0
    def post(self):
        '''
            Add Domain name
        '''
        userid = request.json.get('userid')
        dname = request.json.get('dname')

        u = abort_if_userid_doesnt_exist(userid)
        d = Dname(dname=dname, user=u)

        if dbadd(d):
            return json_message(200, 'message', 'Domain name insert success')
        else:
            return json_message(200, 'error', 'Domain name insert failed')
Beispiel #7
0
    def post(self):
        '''
            Insert domain's record
        '''
        dname_id = request.json.get('dnameid')
        record = request.json.get('record')
        type = request.json.get('type')
        value = request.json.get('value')
        ttl = request.json.get('ttl')

        dnameobj = abort_if_id_doesnt_exist(Dname,id=dname_id)
        recordobj = Record(record=record,type=type,value=value,ttl=ttl,dname=dnameobj)

        if dbadd(recordobj):
            return json_message(200, 'message', 'Record Insert Success')
        else:
            return json_message(200, 'error', 'Record Insert Failed')
Beispiel #8
0
    def delete(self,userid):
        '''
            Delete User
        '''
        abort_if_userid_doesnt_exist(userid)

        dbdel(User, id=userid)

        return json_message(200, 'message', 'User Delete Success')
Beispiel #9
0
    def delete(self, userid):
        '''
            Delete User
        '''
        abort_if_userid_doesnt_exist(userid)

        dbdel(User, id=userid)

        return json_message(200, 'message', 'User Delete Success')
Beispiel #10
0
    def put(self,userid):
        '''
            Update user's password
        '''
        abort_if_userid_doesnt_exist(userid)

        password = request.json.get('password', None)

        if not password:
            return json_message(200, 'error', 'Password is None')

        query = db.session.query(User)
        newpasswd = pwd_context.encrypt(password)

        try:
            query.filter(User.id == userid).update({User.password_hash: newpasswd})
        except Exception:
            return json_message(200, 'error', 'Password Change Failed')

        return json_message(200, 'message', 'Password Change Success')
Beispiel #11
0
    def post(self):
        '''
            Insert domain's record
        '''
        dname_id = request.json.get('dnameid')
        record = request.json.get('record')
        type = request.json.get('type')
        value = request.json.get('value')
        ttl = request.json.get('ttl')

        dnameobj = abort_if_id_doesnt_exist(Dname, id=dname_id)
        recordobj = Record(record=record,
                           type=type,
                           value=value,
                           ttl=ttl,
                           dname=dnameobj)

        if dbadd(recordobj):
            return json_message(200, 'message', 'Record Insert Success')
        else:
            return json_message(200, 'error', 'Record Insert Failed')
Beispiel #12
0
    def put(self, userid):
        '''
            Update user's password
        '''
        abort_if_userid_doesnt_exist(userid)

        password = request.json.get('password', None)

        if not password:
            return json_message(200, 'error', 'Password is None')

        query = db.session.query(User)
        newpasswd = pwd_context.encrypt(password)

        try:
            query.filter(User.id == userid).update(
                {User.password_hash: newpasswd})
        except Exception:
            return json_message(200, 'error', 'Password Change Failed')

        return json_message(200, 'message', 'Password Change Success')
Beispiel #13
0
    def post(self):
        '''
            User Register
        '''
        args = login_parser.parse_args()
        username = args['username']
        password = args['password']

        if not username or not password:
            raise UserOrPassIsNone()

        if User.query.filter_by(username=username).first() is not None:
            return abort(409)

        userobj = User(username=username)
        userobj.hash_password(password)
        dbadd(userobj)

        return json_message(200, 'message', 'User Register Success')
Beispiel #14
0
    def post(self):
        '''
            User Register
        '''
        args = login_parser.parse_args()
        username = args['username']
        password = args['password']

        if not username or not password:
            raise UserOrPassIsNone()

        if User.query.filter_by(username=username).first() is not None:
            return abort(409)

        userobj = User(username=username)
        userobj.hash_password(password)
        dbadd(userobj)

        return json_message(200, 'message', 'User Register Success')
Beispiel #15
0
    def get(self):
        session.clear()

        return json_message(200, 'message', 'Logout Sucess')
Beispiel #16
0
    def get(self):
        session.clear()

        return json_message(200, 'message', 'Logout Sucess')