예제 #1
0
    def citation_put(self):
        """Update an existing citation
        """

        cid = self.request.matchdict['id']

        # validate

        if len(self.data['content']) > 0 and len(self.data['url']) > 0:
            if len(cid) <= 0:
                response = 'Missing parameter (id to be updated)'
                status = False
            else:

                # create database object

                cit = \
                    self.session.query(Citation).filter_by(id=cid).first()
                cit.content = self.data['content']
                cit.url = self.data['url']
                self.session.add(cit)
                response = 'Record updated successfully:' + owner

                # commit change to DB

                self.session.commit()
                status = True
        else:
            response = 'Content or URL missing:' + owner
            status = False

        return ResponseUtils.createResponse(status, response, False,
                self.request, self.format)
예제 #2
0
    def citation_delete(self):
        """Delete an existing citation
        """

        cid = self.request.matchdict['id']

        # validate

        if len(cid) <= 0:
            response = 'Missing parameter (id to be deleted)'
            status = False
        else:

            # create database object

            cit = self.session.query(Citation).filter_by(id=cid).first()
            self.session.delete(cit)

            # commit changes to DB

            self.session.commit()
            status = True
            response = 'Record deleted successfully'

        return ResponseUtils.createResponse(status, response, False,
                                            self.request, self.format)
예제 #3
0
    def user_login(self):
        """Check if user can login
        """

        code = '0'
        if 'form.submitted' in self.request.params:
            if len(self.data['user']) > 0 and len(self.data['password'
                    ]) > 0:
                id = self.data['user']
                salt = ''
                password = hashlib.md5(salt + self.data['password'
                        ]).hexdigest()
                user = \
                    self.session.query(User).filter_by(userID=id).first()
                if user.password == password:
                    headers = remember(self.request, id)
                    return HTTPFound(location='/', headers=headers)
                else:
                    status = False
                    response = 'Login Failed'
            else:
                status = False
                response = 'Login Failed'
            return ResponseUtils.createResponse(
                status,
                code,
                response,
                False,
                self.request,
                self.format,
                headers,
                )
        return dict(message='', url=self.request.application_url
                    + '/login', came_from=self.request.application_url
                    + '/', user='', password='')
예제 #4
0
    def citation_delete(self):
        """Delete an existing citation
        """

        cid = self.request.matchdict['id']

        # validate

        if len(cid) <= 0:
            response = 'Missing parameter (id to be deleted)'
            status = False
        else:

            # create database object

            cit = self.session.query(Citation).filter_by(id=cid).first()
            self.session.delete(cit)

            # commit changes to DB

            self.session.commit()
            status = True
            response = 'Record deleted successfully'

        return ResponseUtils.createResponse(status, response, False,
                self.request, self.format)
예제 #5
0
    def citation_put(self):
        """Update an existing citation
        """

        cid = self.request.matchdict['id']

        # validate

        if len(self.data['content']) > 0 and len(self.data['url']) > 0:
            if len(cid) <= 0:
                response = 'Missing parameter (id to be updated)'
                status = False
            else:

                # create database object

                cit = \
                    self.session.query(Citation).filter_by(id=cid).first()
                cit.content = self.data['content']
                cit.url = self.data['url']
                self.session.add(cit)
                response = 'Record updated successfully:' + owner

                # commit change to DB

                self.session.commit()
                status = True
        else:
            response = 'Content or URL missing:' + owner
            status = False

        return ResponseUtils.createResponse(status, response, False,
                                            self.request, self.format)
예제 #6
0
    def citation_index(self):
        """Display a full list of citation if no ID specified
        """

        cits = None
        cits = self.session.query(Citation).order_by(Citation.id).all()

        return ResponseUtils.createResponse(True, cits, True,
                self.request, self.format)
예제 #7
0
    def citation_index(self):
        """Display a full list of citation if no ID specified
        """

        cits = None
        cits = self.session.query(Citation).order_by(Citation.id).all()

        return ResponseUtils.createResponse(True, cits, True, self.request,
                                            self.format)
예제 #8
0
    def citation_get(self):
        """Display a single citation 
        """

        owner = authenticated_userid(self.request)
        cits = None
        cid = self.request.matchdict['id']
        cits = self.session.query(Citation).filter_by(id=cid).all()
        print ' Got Owner ' + owner
        return ResponseUtils.createResponse(True, cits, True,
                self.request, self.format)
예제 #9
0
    def citation_get(self):
        """Display a single citation 
        """

        owner = authenticated_userid(self.request)
        cits = None
        cid = self.request.matchdict['id']
        cits = self.session.query(Citation).filter_by(id=cid).all()
        print ' Got Owner ' + owner
        return ResponseUtils.createResponse(True, cits, True, self.request,
                                            self.format)
예제 #10
0
    def user_get(self):
        """ Check if a userID exists
        """

        code = 0
        user = None
        try:
            uid = self.request.matchdict['userID']
            user = \
                self.session.query(User).filter_by(userID=uid).first()
            if user != None:
                status = True
                response = 'user exists'
            else:
                status = False
                code = '005'
                response = 'no such user found'
        except KeyError:
            status = False
            code = '001'
            response = 'required fields missing'
        except:
            status = False
            code = '004'
            response = 'internal error'
            (exc_type, exc_value, exc_traceback) = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                    exc_traceback)
            print ''.join('*** ' + line for line in lines)

        return ResponseUtils.createResponse(
            status,
            code,
            response,
            False,
            self.request,
            self.format,
            )
예제 #11
0
    def user_get(self):
        """ Check if a userID exists
        """

        code = 0
        user = None
        try:
            uid = self.request.matchdict['userID']
            user = \
                self.session.query(User).filter_by(userID=uid).first()
            if user != None:
                status = True
                response = 'user exists'
            else:
                status = False
                code = '005'
                response = 'no such user found'
        except KeyError:
            status = False
            code = '001'
            response = 'required fields missing'
        except:
            status = False
            code = '004'
            response = 'internal error'
            (exc_type, exc_value, exc_traceback) = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            print ''.join('*** ' + line for line in lines)

        return ResponseUtils.createResponse(
            status,
            code,
            response,
            False,
            self.request,
            self.format,
        )
예제 #12
0
    def citation_post(self):
        """Create a new citation
        """

        # validate

        if len(self.data['content']) > 0 and len(self.data['url']) > 0:

            # create database object

            cit = Citation(self.data['content'], self.data['url'])
            self.session.add(cit)
            response = 'Record created successfully'

            # commit change to DB

            self.session.commit()
            status = True
        else:
            response = 'Content or URL missing'
            status = False

        return ResponseUtils.createResponse(status, response, False,
                                            self.request, self.format)
예제 #13
0
    def citation_post(self):
        """Create a new citation
        """

        # validate

        if len(self.data['content']) > 0 and len(self.data['url']) > 0:

            # create database object

            cit = Citation(self.data['content'], self.data['url'])
            self.session.add(cit)
            response = 'Record created successfully'

            # commit change to DB

            self.session.commit()
            status = True
        else:
            response = 'Content or URL missing'
            status = False

        return ResponseUtils.createResponse(status, response, False,
                self.request, self.format)
예제 #14
0
    def user_login(self):
        """Check if user can login
        """

        code = '0'
        if 'form.submitted' in self.request.params:
            if len(self.data['user']) > 0 and len(self.data['password']) > 0:
                id = self.data['user']
                salt = ''
                password = hashlib.md5(salt +
                                       self.data['password']).hexdigest()
                user = \
                    self.session.query(User).filter_by(userID=id).first()
                if user.password == password:
                    headers = remember(self.request, id)
                    return HTTPFound(location='/', headers=headers)
                else:
                    status = False
                    response = 'Login Failed'
            else:
                status = False
                response = 'Login Failed'
            return ResponseUtils.createResponse(
                status,
                code,
                response,
                False,
                self.request,
                self.format,
                headers,
            )
        return dict(message='',
                    url=self.request.application_url + '/login',
                    came_from=self.request.application_url + '/',
                    user='',
                    password='')
예제 #15
0
    def register(self):
        """Create a new account
        """

        code = '0'
        try:
            if len(self.data['userID']) > 0 and len(self.data['password'
                    ]) > 0 and len(self.data['email']) > 0 \
                and len(self.data['firstName']) > 0 \
                and len(self.data['lastName']) > 0:

                if self.session.query(User).filter_by(email=self.data['email'
                        ]).first():
                    response = 'email is already registered'
                    code = '003'
                    status = False
                elif self.session.query(User).filter_by(userID=self.data['userID'
                        ]).first():
                    response = 'userID is already registered'
                    code = '002'
                    status = False
                else:

                   # create database object

                    salt = ''  # need to get salt from secret config
                    password = hashlib.md5(salt + self.data['password'
                            ]).hexdigest()
                    user = User(self.data['userID'], password,
                                self.data['email'],
                                self.data['firstName'],
                                self.data['lastName'])
                    self.session.add(user)
                    self.session.flush()
                    secret = SystemUtils.createRandomString()
                    email_code = EmailCode(user.id, secret)
                    self.session.add(email_code)

                   # send a mail to user
                   #Not allowed from ec2     
                   # EmailUtils.sendRegistrationMail(self.data['email'],
                   #         self.data['firstName'], user.id, secret)

                   # commit change to DB

                    self.session.commit()

                    status = True
                    response = 'user registered successfully'
            else:
                response = 'required fields missing'
                code = '001'
                status = False
        except KeyError:
            status = False
            code = '001'
            response = 'required fields missing'
        except:
            status = False
            code = '004'
            response = 'internal error'
            (exc_type, exc_value, exc_traceback) = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                    exc_traceback)
            print ''.join('*** ' + line for line in lines)

        return ResponseUtils.createResponse(
            status,
            code,
            response,
            False,
            self.request,
            self.format,
            )
예제 #16
0
    def register(self):
        """Create a new account
        """

        code = '0'
        try:
            if len(self.data['userID']) > 0 and len(self.data['password'
                    ]) > 0 and len(self.data['email']) > 0 \
                and len(self.data['firstName']) > 0 \
                and len(self.data['lastName']) > 0:

                if self.session.query(User).filter_by(
                        email=self.data['email']).first():
                    response = 'email is already registered'
                    code = '003'
                    status = False
                elif self.session.query(User).filter_by(
                        userID=self.data['userID']).first():
                    response = 'userID is already registered'
                    code = '002'
                    status = False
                else:

                    # create database object

                    salt = ''  # need to get salt from secret config
                    password = hashlib.md5(salt +
                                           self.data['password']).hexdigest()
                    user = User(self.data['userID'], password,
                                self.data['email'], self.data['firstName'],
                                self.data['lastName'])
                    self.session.add(user)
                    self.session.flush()
                    secret = SystemUtils.createRandomString()
                    email_code = EmailCode(user.id, secret)
                    self.session.add(email_code)

                    # send a mail to user
                    #Not allowed from ec2
                    # EmailUtils.sendRegistrationMail(self.data['email'],
                    #         self.data['firstName'], user.id, secret)

                    # commit change to DB

                    self.session.commit()

                    status = True
                    response = 'user registered successfully'
            else:
                response = 'required fields missing'
                code = '001'
                status = False
        except KeyError:
            status = False
            code = '001'
            response = 'required fields missing'
        except:
            status = False
            code = '004'
            response = 'internal error'
            (exc_type, exc_value, exc_traceback) = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            print ''.join('*** ' + line for line in lines)

        return ResponseUtils.createResponse(
            status,
            code,
            response,
            False,
            self.request,
            self.format,
        )
예제 #17
0
    def user_delete(self):
        """Delete an existing user account
        """

        code = '0'
        try:
            uid = self.request.matchdict['userID']
            user = \
                self.session.query(User).filter_by(userID=uid).first()
            if len(self.data['password']) > 0:
                if len(uid) <= 0:
                    response = 'required fields missing'
                    code = '001'
                    status = False
                elif user == None:
                    response = 'no such user found'
                    code = '005'
                    status = False
                else:

                    # create database object

                    salt = ''
                    password = hashlib.md5(salt +
                                           self.data['password']).hexdigest()
                    if user.password == password:
                        self.session.delete(user)
                        response = 'user deleted'

                        # commit change to DB

                        self.session.commit()
                        status = True
                    else:
                        status = False
                        response = 'existing password is incorrect'
            else:
                response = 'required fields missing'
                code = '001'
                status = False
        except KeyError:
            status = False
            code = '001'
            response = 'required fields missing'
        except:
            status = False
            code = '004'
            response = 'internal error'
            (exc_type, exc_value, exc_traceback) = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)
            print ''.join('*** ' + line for line in lines)

        return ResponseUtils.createResponse(
            status,
            code,
            response,
            False,
            self.request,
            self.format,
        )
예제 #18
0
    def user_delete(self):
        """Delete an existing user account
        """

        code = '0'
        try:
            uid = self.request.matchdict['userID']
            user = \
                self.session.query(User).filter_by(userID=uid).first()
            if len(self.data['password']) > 0:
                if len(uid) <= 0:
                    response = 'required fields missing'
                    code = '001'
                    status = False
                elif user == None:
                    response = 'no such user found'
                    code = '005'
                    status = False
                else:

                   # create database object

                    salt = ''
                    password = hashlib.md5(salt + self.data['password'
                            ]).hexdigest()
                    if user.password == password:
                        self.session.delete(user)
                        response = 'user deleted'

                      # commit change to DB

                        self.session.commit()
                        status = True
                    else:
                        status = False
                        response = 'existing password is incorrect'
            else:
                response = 'required fields missing'
                code = '001'
                status = False
        except KeyError:
            status = False
            code = '001'
            response = 'required fields missing'
        except:
            status = False
            code = '004'
            response = 'internal error'
            (exc_type, exc_value, exc_traceback) = sys.exc_info()
            lines = traceback.format_exception(exc_type, exc_value,
                    exc_traceback)
            print ''.join('*** ' + line for line in lines)

        return ResponseUtils.createResponse(
            status,
            code,
            response,
            False,
            self.request,
            self.format,
            )