Exemple #1
0
def isCorrectUserPassword(user, password):
    try:
        salt = securityservice.extractSaltFromPassword(password=user["password"])
        hashedPassword = securityservice.hash(value=password, salt=salt)

        if user["password"] != hashedPassword:
            return (False, None)

    except Exception as e:
        return (False, e.message)

    return (True, None)
Exemple #2
0
def createUser(email, password, firstName, lastName):
    hashedPassword = securityservice.hash(value=password)

    id = database.execute(
        sql="""
		INSERT INTO user (
			  email
			, password
			, firstName
			, lastName
		) VALUES (
			  %s
			, %s
			, %s
			, %s
		)
	""",
        parameters=(email, hashedPassword, firstName, lastName),
    )

    return newUserBean(id=id, email=email, password=hashedPassword, firstName=firstName, lastName=lastName)
Exemple #3
0
def setupDatabase(dbServer, dbPort, dbName, dbUser, dbPass, email, password, firstName, lastName, timezone, hashKey1, hashKey2):
	#
	# TODO: This code is MySQL specific. I would like to
	# support other engines at some point
	#
	database.connect(
		engine   = "mysql",
		host     = dbServer,
		port     = dbPort,
		database = "mysql",
		user     = dbUser,
		password = dbPass
	)

	database.execute("DROP DATABASE IF EXISTS %s;" % dbName)
	database.execute("CREATE DATABASE %s;" % dbName)
	database.execute("USE %s;" % dbName)

	database.execute("""
		CREATE TABLE `settings` (
			`themeName` VARCHAR(50) NOT NULL DEFAULT 'default',
			`timezone` VARCHAR(50) NOT NULL DEFAULT 'UTC'
		) ENGINE=MyISAM;
	""")

	database.execute("""
		CREATE TABLE awssettings (
			accessKeyId VARCHAR(50),
			secretAccessKey VARCHAR(50),
			s3Bucket VARCHAR(100)
		) ENGINE=MyISAM;
	""")

	database.execute("""
		CREATE TABLE `user` (
			`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
			`email` VARCHAR(255) NOT NULL UNIQUE,
			`password` VARCHAR(255) NOT NULL,
			`firstName` VARCHAR(50) NOT NULL,
			`lastName` VARCHAR(50) NOT NULL
		) ENGINE=MyISAM;
	""")

	database.execute("CREATE INDEX `idx_user_email` ON `user` (`email`);")

	database.execute("""
		CREATE TABLE `poststatus` (
			`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
			`status` VARCHAR(20) NOT NULL
		) ENGINE=MyISAM;
	""")

	database.execute("""
		CREATE TABLE `post` (
			`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
			`title` VARCHAR(175) NOT NULL,
			`authorId` INT UNSIGNED NOT NULL,
			`slug` VARCHAR(300) NOT NULL,
			`content` TEXT,
			`createdDateTime` DATETIME,
			`publishedDateTime` DATETIME,
			`publishedYear` INT,
			`publishedMonth` INT,
			`postStatusId` INT UNSIGNED,

			FOREIGN KEY (authorId) REFERENCES user(id),
			FOREIGN KEY (postStatusId) REFERENCES poststatus(id)
		) ENGINE=MyISAM;
	""")

	database.execute("CREATE INDEX `idx_post_publishedDateTime` ON `post` (`publishedDateTime`);")

	database.execute("""
		CREATE TABLE `posttag` (
			`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
			`tag` VARCHAR(20) NOT NULL,
			`howManyTimesUsed` INT NOT NULL DEFAULT 0,

			UNIQUE KEY `posttag_tag` (`tag`)
		) ENGINE=MyISAM;
	""")

	database.execute("CREATE INDEX `idx_posttag_tag` ON `posttag` (`tag`);")

	database.execute("""
		CREATE TABLE `post_posttag` (
			`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
			`postId` INT UNSIGNED NOT NULL,
			`postTagId` INT UNSIGNED NOT NULL,

			UNIQUE KEY `post_posttag_unique_tagandid` (`postId`, `postTagId`),
			FOREIGN KEY (`postId`) REFERENCES post(`id`),
			FOREIGN KEY (`postTagId`) REFERENCES posttag(`id`)
		) ENGINE=MyISAM;
	""")

	database.execute("""
		INSERT INTO settings (themeName, timezone) VALUES
			('default', %s)
		;
	""", (
		timezone,
	))

	database.execute("""
		INSERT INTO user (email, password, firstName, lastName) VALUES
			(%s, %s, %s, %s)
		;
	""", (
		email,
		securityservice.hash(value=password, hashKey1=hashKey1, hashKey2=hashKey2),
		firstName,
		lastName,
	))

	database.execute("""
		INSERT INTO poststatus (status) VALUES
			('Draft'),
			('Published'),
			('Archived')
		;
	""")

	database.execute("""
		INSERT INTO awssettings (accessKeyId, secretAccessKey, s3Bucket) VALUES ('', '', '');
	""")