IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[SPWEB_ONAYKODDOGRULA]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE SPWEB_ONAYKODDOGRULA
GO

CREATE PROCEDURE [dbo].[SPWEB_ONAYKODDOGRULA]
	@Phone nvarchar(20),
	@Email nvarchar(100),
	@ConfirmCode nvarchar(20)
AS
BEGIN
	IF (SELECT COUNT(*) FROM HWEBONAYKOD WHERE ((@Phone<>'' AND HCEP=@Phone) OR (@Email<>'' AND HEMAIL=@Email)) AND ONAYKODU=@ConfirmCode AND KAYITTARIHI>DATEADD(MINUTE,-30,GETDATE()))>0
	BEGIN
		SELECT 1 AS result, 'Onay kodu doğru' as resultdesc
	END
	ELSE
	BEGIN
		SELECT 6 AS result, 'Onay kodu yanlış' as resultdesc
	END
END
GO

IF EXISTS (SELECT [name] FROM [sys].[database_principals] WHERE [type] = N'S' AND [name] = N'mediwebuser')
BEGIN
	BEGIN TRY
		GRANT EXECUTE ON [dbo].[SPWEB_ONAYKODDOGRULA] TO [mediwebuser]
	END TRY
	BEGIN CATCH
	END CATCH
END
GO

