achievements_project/sql/AuthProcs.sql

56 lines
2.2 KiB
MySQL
Raw Permalink Normal View History

2021-02-16 19:11:12 +00:00
<EFBFBD><EFBFBD>-----------------------
-- CREATE A NEW USER --
-----------------------
CREATE PROCEDURE [CreateUser] (
2021-02-06 01:19:11 +00:00
@email VARCHAR(254),
@username VARCHAR(32),
@salt CHAR(32),
@password CHAR(64),
@ID INT OUTPUT,
@Hue INT OUTPUT
2021-02-04 15:56:33 +00:00
) AS
IF EXISTS (SELECT Email FROM [User] WHERE Email = @email)
BEGIN
2021-02-05 09:59:17 +00:00
PRINT 'Email is already registered with an account.'
2021-02-04 15:56:33 +00:00
RETURN 1
END
IF @username IS NULL
BEGIN
PRINT 'Username cannot be null'
RETURN 2
END
IF @password IS NULL
BEGIN
PRINT 'Password cannot be null'
RETURN 3
END
IF @salt IS NULL
BEGIN
PRINT 'Password salt cannot be null'
RETURN 4
END
2021-02-04 15:56:33 +00:00
2021-02-05 09:59:17 +00:00
INSERT INTO [User](Email, Username, Salt, [Password]) VALUES (@email, @username, @salt, @password)
2021-02-06 01:19:11 +00:00
SET @ID = @@IDENTITY
2021-02-16 19:11:12 +00:00
SELECT @Hue = Hue FROM [User] WHERE ID = @ID
2021-02-04 15:56:33 +00:00
RETURN 0
2021-02-16 19:11:12 +00:00
GO
-------------------------
-- GET USER LOGIN INFO --
-------------------------
2021-02-04 15:56:33 +00:00
2021-02-16 19:11:12 +00:00
CREATE PROCEDURE GetUserLogin(
@email VARCHAR(254)
) AS
IF NOT @email IN (SELECT Email FROM [User])
BEGIN
PRINT 'No user exists with specified email'
RETURN 1
END
SELECT Id, Salt, [Password], Hue, [Admin] FROM [User] WHERE Email = @email
RETURN 0
GO