Пример #1
0
    def _make_media_path(self, media_id, host, username=None, width=None, height=None, crop=None):
        """
		Makes a path to an image.

		@param media_id: ID of the image
		@type media_id: String

		@param host: Host that holds the image
		@type host: String

		@param username: User who modified the image (if applicable)
		@type username: String

		@param width: Width of the render
		@type width: Integer

		@param height: Height of the render
		@type height: Integer

		@param crop: Whether or not the render is cropped
		@type crop: Integer
		"""
        try:
            media_id = validation.media_id(media_id)
            validation.required(host, "host")
            if username:
                username = validation.username(username, "username")
            if width:
                width = validation.cast_integer(width, "width")
                height = validation.cast_integer(height, "height")
                crop = validation.cast_boolean(crop, "crop")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
Пример #2
0
	def _make_media_path(self, media_id, host, username=None, width=None, height=None, crop=None):
		"""
		Makes a path to an image.

		@param media_id: ID of the image
		@type media_id: String

		@param host: Host that holds the image
		@type host: String

		@param username: User who modified the image (if applicable)
		@type username: String

		@param width: Width of the render
		@type width: Integer

		@param height: Height of the render
		@type height: Integer

		@param crop: Whether or not the render is cropped
		@type crop: Integer
		"""
		try:
			media_id = validation.media_id(media_id)
			validation.required(host, 'host')
			if username:
				username = validation.username(username, 'username')
			if width:
				width = validation.cast_integer(width, 'width')
				height = validation.cast_integer(height, 'height')
				crop = validation.cast_boolean(crop, 'crop')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Пример #3
0
	def user_owns_image(self, media_id, owner_username):
		"""
		Determines if a particular user owns an image.

		@param media_id: Media ID to check.
		@type media_id: String

		@param owner_username: User to check ownership for.
		@type owner_username: String

		@return: Whether or not the specified user owns a copy of the image.
		@rtype: Boolean
		"""
		media_id = validation.media_id(media_id)
		owner_username = validation.username(owner_username)

		@stack
		def format_result(result):
			return result['zoto_user_owns_image']

		d = self.app.db.query("""
			select zoto_user_owns_image(zoto_get_user_id(%s), %s)
			""", (owner_username, media_id), single_row=True)
		d.addCallback(format_result)
		return d
Пример #4
0
    def add_password_token(self, username):
        """ It's lame, but so is Qoop """
        username = validation.username(username)

        # make a new key, or update the expiration of an existing one
        data = {
            "username":
            username,
            "user_token":
            md5("%s%s" % (username, time.time())).hexdigest(),
            "password_token":
            md5("%s%s" %
                (md5("%s%s" %
                     (username, time.time())), time.time())).hexdigest()
        }
        d = self.app.db.query("""
			insert into
				qoop_tokens (
					username,
					user_token,
					password_token,
					expires
				) values (
					%(username)s,
					%(user_token)s,
					%(password_token)s,
					DATE_ADD(now(), INTERVAL 2 HOUR)
				)
			on duplicate key
				update 
					expires = DATE_ADD(now(), INTERVAL 2 HOUR)
			""",
                              data,
                              database='cluster')

        # first see if there is already a key we can use
        def find_token(void):
            d2 = self.app.db.query("""
				select
					user_token
				from
					qoop_tokens
				where
					username = %s
					and
					expires > now()
				""", (username, ),
                                   database='cluster')
            d2.addCallback(result_mods.return_1st_cell)
            return d2

        d.addCallback(self.collect_garbage)
        d.addCallback(find_token)
        return d
Пример #5
0
	def post(self):
		user_username = self.request.get('username')
		user_password = self.request.get('password')
		user_verify = self.request.get('verify')
		user_email = self.request.get('email')
		venmo_email = self.request.get('venmo_email')
		bio = self.request.get('bio')

		username = validation.username(user_username)
		password = validation.password(user_password)
		verify = validation.verify(user_verify, user_password)
		email = validation.edu_email(user_email)
		venmo_email_verify = validation.email(venmo_email)

		userError=""
		passError=""
		verifyError=""
		emailError=""
		venmoEmailError = ""
		if not username:
			userError = "That's not a valid username."
			user_username=""
		if not password:
			passError = "That wasn't a valid password."
		if not verify:
			verifyError = "Your passwords didn't match."
		if not email:
			emailError = "That's not a valid email."
			user_email=""
		if venmo_email != "" and venmo_email_verify is None:
			venmoEmailError = "That's not a valid email. Leave empty if you don't have one"
			venmo_email=""
		
		if username and password and verify and email and (venmoEmailError == ""):
			passHash = validation.make_pw_hash(username, password)
			code = validation.make_salt()

			user = User(username = username, passHash=passHash, email=email, bio=bio, venmo_email=venmo_email, activationCode=code)
				
			u = User.all().filter('username ='******'Content-Type'] = 'text/plain'
			cookie_val = validation.make_secure_val(str(user_id))
			self.response.headers.add_header('Set-Cookie',str('user=%s; Path=/' % cookie_val))
			self.sendActivationEmail(email, code)
			self.redirect("/home")
		else:
			self.write_form(userError, passError, verifyError, emailError, venmoEmailError,
						user_username, user_email, bio=bio)
Пример #6
0
    def __init__(self,
                 username,
                 name,
                 password_hash=None,
                 password="******"):
        self.username = valid.username(username)
        self.name = valid.name(name)

        if password_hash:
            self.password_hash = password_hash
        else:
            self.password_hash = hashlib.sha512(password).hexdigest()(username)
Пример #7
0
    def check_feature(self, username, feature):
        """
		See if a user account has a particular feature enabled

		@param username: The username we are checking
		@type username: String

		@param feature: one of the account constants from constants.py
		@type feature: String
		
		@return: 1 if the feature is enabled for the user, 0 if not
		@rtype: Integer
		"""
        self.log.debug("checking if user %s has %s enabled" %
                       (username, feature))

        # valid username?
        username = validation.username(username)

        # valid feature?
        validation.oneof(feature, self.valid_features, "feature")

        # immediately return true for reserved names
        if username in self.app.api.users._cfg_invalid_usernames.split():
            return 1

        # get their account info
        self.log.debug("getting account info for %s" % username)
        d = self.app.api.users.get_account_info(username)

        # check the feature
        def check(account_info, feature):
            if account_info.get("account_status", {}).has_key(feature):
                enabled = account_info.get("account_status",
                                           {}).get(feature, 0)
            else:
                enabled = account_info.get("account_type", {}).get(feature, 0)
            if enabled:
                # they have the feature
                self.log.debug("user %s has %s enabled" % (username, feature))
                try:
                    enabled = int(enabled)
                    return enabled
                except:
                    return 1
            else:
                # they have the feature
                self.log.debug("user %s has %s disabled" % (username, feature))
                return 0

        d.addCallback(check, feature)
        return d
Пример #8
0
def create_student(request, *args, **kwargs):

    data = JSONParser().parse(request)
    
    std_id = data.get('sid')
    username = data.get('username')
    name = data.get('name')
    password = data.get('password')

    # If any of the values are not consistent with what is stored, then a response
    # is returned saying "parameters are missing" and an error code 400 is returned.
    if not (std_id and username and name and password):
        return Response({"message": "Parameters missing"}, status=400)

    try:
        std_id = validation.sid(std_id)
    except ValueError:
        return Response({"message": "Invalid student ID"}, status=400)

    try:
        username = validation.username(username)
    except ValueError:
        return Response({"message": "Invalid Username"}, status=400)

    try:
        name = validation.name(name)
    except ValueError:
        return Response({"message": "Invalid Name"}, status=400)


    try:
        std = Student.objects.filter(sid=std_id)

        if std.exists():
            return Response({"message": f"Student already exist with student id {std_id}."}, status=404)
            

        student = Student.objects.create(
            sid=std_id,
            username=username, 
            name=name,
            pass_hash=make_password(password)
        )

        return Response({"msg": "Success"} ,status=200)

    except Exception as e:
        print(e)
        return Response({"message": "Can't Create Studeny"} ,status=200)
Пример #9
0
	def get_image_id(self, owner_username, media_id):
		"""
		Gets a numeric image_id based on the owner/media combination.

		@param owner_username: Owner of the image
		@type owner_username: String

		@param media_id: Hash identifier for the media
		@type media_id: String
		"""
		try:
			owner_username = validation.username(owner_username, 'owner_username')
			media_id = validation.media_id(media_id)
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Пример #10
0
    def clear_renders(self, media_id, owner_username, node):
        """
		Clears out all the renders for a particular user's image.

		@param media_id: ID of the media being cleared
		@type media_id: String

		@param owner_username: User who owns the image
		@type owner_username: String
		"""
        try:
            media_id = validation.media_id(media_id)
            owner_username = validation.username(owner_username)
            validation.required(node, "node")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
Пример #11
0
	def clear_renders(self, media_id, owner_username, node):
		"""
		Clears out all the renders for a particular user's image.

		@param media_id: ID of the media being cleared
		@type media_id: String

		@param owner_username: User who owns the image
		@type owner_username: String
		"""
		try:
			media_id = validation.media_id(media_id)
			owner_username = validation.username(owner_username)
			validation.required(node, 'node')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Пример #12
0
def create_lecturer(request, *args, **kwargs):

    data = JSONParser().parse(request)

    username = data.get('username')
    name = data.get('name')
    password = data.get('password')

    # If any of the values are not consistent with what is stored, then a response
    # is returned saying "parameters are missing" and an error code 400 is returned.
    if not (username and name and password):
        return Response({"message": "Parameters missing"}, status=400)

    try:
        username = validation.username(username)
    except ValueError:
        return Response({"message": "Invalid Username"}, status=400)

    try:
        name = validation.name(name)
    except ValueError:
        return Response({"message": "Invalid Name"}, status=400)


    try:
        lec = Lecturer.objects.filter(username=username)

        if lec.exists():
            return Response({"message": f"lecturer already exist with username {username}."}, status=404)
            

        lecturer = Lecturer.objects.create(
                    username=username, 
                    name=name,
                    pass_hash=make_password(password)
            )

        return Response({"msg": "Success"} ,status=200)

    except Exception as e:
        print(e)
        return Response({"message": "Can't create lecturer"} ,status=200)
Пример #13
0
	def _generate_render_paths(self, media_id, host, username=None):
		"""
		Generates all possible render storage for the given host/media_id/username.

		@param media_id: ID of the media rendered
		@type media_id: String

		@param host: Host the render is stored on
		@type host: String

		@param username: Specific username, if applicable
		@type username: String (or None)
		"""
		try:
			media_id = validation.media_id(media_id)
			validation.required(host, 'host')
			if username:
				username = validation.username(username, 'username')
		except errors.ValidationError, ex:
			return utils.return_deferred_error(ex.value)
Пример #14
0
    def get_media_info(self, media_id, username=None, binary_data=False):
        """
		Fetch the binary data of a given media_id

		@param media_id: the media_id you are trying to find
		@type media_id: String

		@param username: If specified find this user's most up to date version
			of the media (replaces our old filter-hash concept)
		@type username: String

		@return: binary media data, media type, and size
		@rtype: 3 element tuple
		"""
        try:
            media_id = validation.media_id(media_id)
            if username:
                username = validation.username(username, "username")
        except errors.ValidationError, ex:
            return utils.returnDeferredError(ex.value)
Пример #15
0
    def _generate_render_paths(self, media_id, host, username=None):
        """
		Generates all possible render storage for the given host/media_id/username.

		@param media_id: ID of the media rendered
		@type media_id: String

		@param host: Host the render is stored on
		@type host: String

		@param username: Specific username, if applicable
		@type username: String (or None)
		"""
        try:
            media_id = validation.media_id(media_id)
            validation.required(host, "host")
            if username:
                username = validation.username(username, "username")
        except errors.ValidationError, ex:
            return utils.return_deferred_error(ex.value)
Пример #16
0
	def get_media_info(self, media_id, username=None, binary_data=False):
		"""
		Fetch the binary data of a given media_id

		@param media_id: the media_id you are trying to find
		@type media_id: String

		@param username: If specified find this user's most up to date version
			of the media (replaces our old filter-hash concept)
		@type username: String

		@return: binary media data, media type, and size
		@rtype: 3 element tuple
		"""
		try:
			media_id = validation.media_id(media_id)
			if username:
				username = validation.username(username, 'username')
		except errors.ValidationError, ex:
			return utils.returnDeferredError(ex.value)
Пример #17
0
 def __init__(self, sid, name, username):
     self.sid = valid.sid(sid)
     self.name = valid.name(name)
     self.username = valid.username(username)
Пример #18
0
 def __init__(self, event_id, room, start, end, lecturer):
     self.event_id = event_id
     self.room = room
     self.start = start
     self.end = end
     self.lecturer = valid.username(lecturer)