You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

466 lines
32 KiB

1 year ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_online_customer_login] Script Date: 9/27/2019 1:30:14 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_online_customer_login]
  9. @flag VARCHAR(50)
  10. ,@customerEmail VARCHAR(100) = NULL
  11. ,@customerPassword VARCHAR(255) = NULL
  12. ,@country VARCHAR(50) = NULL
  13. ,@ipAddress VARCHAR(100) = NULL
  14. ,@lockReason VARCHAR(500) = NULL
  15. ,@UserInfoDetail VARCHAR(MAX) = NULL
  16. ,@sessionId VARCHAR(60) = NULL
  17. ,@checkCountry VARCHAR(50) = NULL
  18. ,@password VARCHAR(50) = NULL
  19. ,@idType VARCHAR(50) = NULL
  20. ,@idNumber VARCHAR(50) = NULL
  21. AS
  22. SET NOCOUNT ON;
  23. SET XACT_ABORT ON;
  24. BEGIN TRY
  25. DECLARE
  26. @UserData VARCHAR(200)
  27. ,@lastPwdChangedOn DATETIME
  28. ,@forceChangePwd CHAR(1)
  29. ,@pwdChangeDays VARCHAR(20)
  30. ,@msg VARCHAR(2000)
  31. ,@pwdChangeWarningDays VARCHAR(5)
  32. ,@lastLoginDate DATETIME
  33. DECLARE @email VARCHAR(100)
  34. ,@customerPwd VARCHAR(50)
  35. ,@isActive CHAR(1)
  36. ,@onlineUser CHAR(1)
  37. ,@isLocked VARCHAR(1)
  38. ,@ccountry VARCHAR(50)
  39. ,@customerStatus CHAR(1)
  40. ,@loginAttempt INT
  41. IF @flag = 'check-id'
  42. BEGIN
  43. IF EXISTS(SELECT FULLNAME FROM CUSTOMERMASTER (NOLOCK) WHERE IDNUMBER = @idNumber) OR
  44. EXISTS(SELECT 'x' FROM dbo.CustomerMasterTemp AS CM(NOLOCK) WHERE IDNUMBER = @idNumber AND createdBy IS NOT NULL)
  45. BEGIN
  46. SELECT 1 ERRORCODE,'Already exists!' MSG,NULL
  47. RETURN
  48. END
  49. SELECT 0 ERRORCODE,'Success' MSG,NULL
  50. RETURN
  51. END
  52. IF @flag = 'checkIp'
  53. BEGIN
  54. IF NOT EXISTS( SELECT COUNTRYNAME FROM COUNTRYMASTER WITH (NOLOCK)
  55. WHERE ISNULL(allowOnlineCustomer,'N')='Y' AND upper(COUNTRYNAME)=upper(@checkCountry))
  56. BEGIN
  57. SELECT 1 ERRORCODE,'NOT AVAILABLE' MSG,NULL
  58. RETURN
  59. END
  60. ELSE
  61. BEGIN
  62. SELECT 0 ERRORCODE,'AVAILABLE' MSG,NULL
  63. END
  64. END
  65. IF @flag = 'l'
  66. BEGIN
  67. IF NOT EXISTS(SELECT 'x' FROM customerMaster WITH(NOLOCK) WHERE email=@customerEmail)
  68. BEGIN
  69. SELECT 1 errorCode, 'Login Failed - Invalid username or password!' mes, @customerEmail id
  70. RETURN
  71. END
  72. SELECT @email=email,
  73. @customerPwd=customerPassword,
  74. @isActive=isactive,
  75. @onlineUser=onlineuser,
  76. @isLocked=isLocked,
  77. @ccountry=country,
  78. @customerStatus=customerStatus,
  79. @lastLoginDate=lastLoginTs,
  80. @loginAttempt = ISNULL(invalidAttemptCount, 0)
  81. FROM customerMaster WITH (NOLOCK)
  82. WHERE email=@customerEmail and ISNULL(onlineUser, 'N')='Y'
  83. SET @UserData ='User: '+ @customerEmail +' User Type:Online User'
  84. DECLARE @attemptsCount INT, @InvalidReason VARCHAR(80), @InvalidMsg VARCHAR(100)
  85. SELECT TOP 1 @attemptsCount = loginAttemptCount FROM passwordFormat WITH(NOLOCK)
  86. IF (ISNULL(@isLocked, 'N') IN ('B', 'Y')) OR ((@loginAttempt - @attemptsCount) = -1)
  87. BEGIN
  88. SET @UserInfoDetail = 'Reason = Too many wrong attempts .-:::-' + @UserInfoDetail
  89. SELECT 1 errorCode, 'Login Failed - Too many wrong attempts, please contact GME Support!' mes, @customerEmail id, @attemptsCount ac
  90. EXEC proc_applicationLogs
  91. @flag='login',
  92. @logType='Login fails',
  93. @createdBy = @customerEmail,
  94. @Reason= 'Reason = Too many wrong attempts.',
  95. @UserData = @UserData,
  96. @fieldValue = @UserInfoDetail,
  97. @IP = @ipAddress
  98. RETURN
  99. END
  100. IF (@customerPwd <> dbo.FNAEncryptString(@customerPassword))
  101. BEGIN
  102. SET @UserInfoDetail = 'Reason = Incorrect password .-:::-' + @UserInfoDetail
  103. SET @loginAttempt = @loginAttempt + 1
  104. UPDATE customerMaster SET invalidAttemptCount = @loginAttempt--, isLocked = CASE WHEN @loginAttempt > @attemptsCount THEN 'B' ELSE 'N' END
  105. WHERE email = @customerEmail and ISNULL(onlineUser, 'N')='Y'
  106. SET @InvalidReason = CASE WHEN @loginAttempt > @attemptsCount THEN 'Number of invalid password attempts exceeded!' ELSE 'Invalid Password' END
  107. SET @InvalidMsg = 'Login Failed - you have ' + CAST((@attemptsCount - @loginAttempt) AS VARCHAR) + ' Attempts Left'
  108. SELECT 1 errorCode, @InvalidMsg mes, @customerEmail id, @attemptsCount ac
  109. EXEC proc_applicationLogs
  110. @flag='login',
  111. @logType='Login fails',
  112. @createdBy = @customerEmail,
  113. @Reason= @InvalidReason,
  114. @UserData = @UserData,
  115. @fieldValue = @UserInfoDetail,
  116. @IP = @ipAddress
  117. RETURN
  118. END
  119. IF (ISNULL(@onlineUser, 'N') = 'N')
  120. BEGIN
  121. SELECT 2 errorCode, 'User is not an Online User' mes, @customerEmail id, @attemptsCount ac
  122. SET @UserInfoDetail = 'Reason = Login fails, Invalid password.-:::-'+@UserInfoDetail
  123. EXEC proc_applicationLogs
  124. @flag='login',
  125. @logType='Login fails',
  126. @createdBy = @customerEmail,
  127. @Reason='Not online User',
  128. @UserData = @UserData,
  129. @fieldValue = @UserInfoDetail,
  130. @IP = @ipAddress
  131. RETURN
  132. END
  133. DECLARE @vPenny CHAR(1),@vCustomerId BIGINT
  134. SELECT @vCustomerId=CM.customerId , @vPenny = CASE WHEN CM.createdDate < '2018-12-19 11:00:00' THEN 'N' WHEN ISNULL(CC.action,'REQ') = 'REQ' THEN 'Y' ELSE 'N' END
  135. from customerMaster CM (nolock)
  136. LEFT JOIN TblCustomerBankVerification CC (nolock) ON CM.customerId = CC.customerId
  137. WHERE CM.email = @customerEmail
  138. IF @vPenny = 'Y'
  139. BEGIN
  140. SELECT 1000 errorCode, 'User redirect to penny test verification' mes, @vCustomerId id
  141. SET @UserInfoDetail = 'Reason = Login fails, User redirect to penny test verification.-:::-'+@UserInfoDetail
  142. EXEC proc_applicationLogs
  143. @flag='login',
  144. @logType='Login fails',
  145. @createdBy = @customerEmail,
  146. @Reason='Penny test verification',
  147. @UserData = @UserData,
  148. @fieldValue = @UserInfoDetail,
  149. @IP = @ipAddress
  150. RETURN
  151. END
  152. IF (ISNULL(@isActive, 'Y') = 'N')
  153. BEGIN
  154. SELECT 1 errorCode, 'Your account is Inactive. Please, contact GME Support Team.' mes, @customerEmail id
  155. SET @UserInfoDetail = 'Reason = Login fails, Your account is Inactive. Please, contact your administrator.-:::-'+@UserInfoDetail
  156. EXEC proc_applicationLogs
  157. @flag='login',
  158. @logType='Login fails',
  159. @createdBy = @customerEmail,
  160. @Reason='User is not active ',
  161. @UserData = @UserData,
  162. @fieldValue = @UserInfoDetail,
  163. @IP = @ipAddress
  164. RETURN
  165. END
  166. IF EXISTS (SELECT 'x' FROM customerMaster (NOLOCK) WHERE email=@customerEmail AND approvedBy IS NULL AND approvedDate IS NULL)
  167. BEGIN
  168. SELECT 1 errorCode, 'Login Failed - Customer registration verification pending please visit nearest GME branch to get verified!' mes, @customerEmail id
  169. RETURN
  170. END
  171. UPDATE customerMaster SET
  172. sessionId=@sessionId
  173. ,lastLoginTs = GETDATE()
  174. ,invalidAttemptCount = 0
  175. WHERE email = @customerEmail and ISNULL(onlineUser, 'N')='Y'
  176. DECLARE @mobileNo VARCHAR(16)
  177. SET @mobileNo = REPLACE(@mobileNo,' ','')
  178. SET @mobileNo = REPLACE(@mobileNo,'-','')
  179. SET @mobileNo = REPLACE(@mobileNo,'+','')
  180. SET @mobileNo = LEFT(@mobileNo,16)
  181. DECLARE @clientUseCode VARCHAR(10), @clientId VARCHAR(50), @clientSecret VARCHAR(50), @accessToken VARCHAR(400), @gmeBankCode VARCHAR(3), @gmeAccountNo VARCHAR(20)
  182. SELECT @clientUseCode = DBO.DECRYPTDB(clientUseCode), @clientId = DBO.DECRYPTDB(clientId), @clientSecret = DBO.DECRYPTDB(clientSecret)
  183. , @accessToken = accessToken, @gmeAccountNo = accountNum, @gmeBankCode = bankCodeStd
  184. FROM KFTC_GME_MASTER (NOLOCK)
  185. SELECT
  186. TOP 1
  187. 0 errorCode
  188. ,'Login success.' mes
  189. ,cu.customerId Id
  190. ,username = cu.email
  191. ,fullName = cu.fullName
  192. ,country = cm.countryName
  193. ,agent_branch_code=cu.branchId
  194. ,agentcode=cu.agentId
  195. ,date_format=NULL
  196. ,limitPerTran=0
  197. ,GMT_value=NULL
  198. ,currencyType=NULL
  199. ,extra_rate_bank=NULL
  200. ,cash_ledger_id=NULL
  201. ,@attemptsCount [ac]
  202. ,sessionTimeOutPeriod=NULL
  203. ,lastLoginTs=GETDATE()
  204. ,cm.countryId
  205. ,[address] = cu.city +'-Provience,South Korea'
  206. ,[address2]=cu.[address2]
  207. ,homePhone=cu.homePhone
  208. ,mobile=cu.mobile
  209. ,cm.countryCode
  210. ,utcTime=8
  211. ,mobile= @mobileNo
  212. ,city=cu.city
  213. ,postalCode=cu.postalCode
  214. ,membershipId=membershipId
  215. ,sdv.detailTitle idType
  216. ,cu.idNumber
  217. ,isForcedPwdChange = ISNULL(isForcedPwdChange,0)
  218. ,customerStatus
  219. ,cu.walletAccountNo
  220. ,primaryBankName=CASE WHEN cu.customerType='11048' THEN 'Mutual savings bank(050)' ELSE 'Kwangju Bank (034)' END
  221. ,nativeCountry = cm1.countryName
  222. ,nativeCountryId = cm1.countryId
  223. ,nativeCountryCode = cm1.countryCode
  224. ,occupation = sd.detailTitle
  225. ,idExpiryDate = CASE WHEN cu.idType='8008' THEN '2059-12-12' ELSE FORMAT(cu.idExpiryDate,'MM/dd/yyyy') END
  226. ,birthDate = FORMAT(cu.dob,'MM/dd/yyyy')
  227. ,accessToken = KFTC.accessToken
  228. ,clientUseCode = @clientUseCode
  229. ,clientId = @clientId
  230. ,clientSecret = @clientSecret
  231. ,gmeAccessToken = @accessToken
  232. ,gmeBankCode = @gmeBankCode
  233. ,gmeAccountNum = @gmeAccountNo
  234. FROM customerMaster cu WITH(NOLOCK)
  235. LEFT JOIN countryMaster cm WITH (NOLOCK) ON cm.countryId=cu.country
  236. LEFT JOIN countryMaster cm1 with(nolock) on cm1.countryId = cu.nativeCountry
  237. left join staticDataValue sdv with (nolock) on sdv.valueId=cu.idType
  238. left join staticDataValue sd with(nolock) on sd.valueId = cu.occupation
  239. LEFT JOIN dbo.vwBankLists vwbank WITH (NOLOCK) ON cu.bankName=vwbank.rowid
  240. LEFT JOIN KFTC_CUSTOMER_MASTER KFTC(NOLOCK) ON KFTC.customerId = CU.customerId
  241. WHERE cu.email= @customerEmail
  242. and ISNULL(cu.onlineUser, 'N')='Y'
  243. EXEC proc_applicationLogs
  244. @flag='login',
  245. @logType='Login',
  246. @createdBy = @customerEmail,
  247. @Reason='Login',
  248. @UserData = @UserData,
  249. @fieldValue = @UserInfoDetail,
  250. @IP = @ipAddress
  251. END
  252. ELSE IF @flag = 'loc'
  253. BEGIN
  254. UPDATE customerMaster SET
  255. isLocked = 'Y'
  256. WHERE email= @customerEmail and ISNULL(onlineUser, 'N')='Y'
  257. INSERT INTO userLockHistory(userName, lockReason, createdBy, createdDate)
  258. SELECT @customerEmail, @lockReason, 'system',GETDATE()
  259. SELECT 0 errorCode, 'Your account has been locked. Please, contact your administrator.' mes, @customerEmail id
  260. END
  261. ELSE IF @flag='availbal'
  262. BEGIN
  263. SELECT ISNULL(availableBalance, 0.00) AS availableBalance FROM dbo.customerMaster(nolock)
  264. WHERE email=@customerEmail
  265. --SELECT 0 errorCode,ISNULL(a.clr_bal_amt, 0.00) AS availableBalance
  266. --FROM dbo.customerMaster c(nolock)
  267. --INNER JOIN FastMoneyPro_account.dbo.ac_master a(nolock) ON A.acct_num = c.walletAccountNo
  268. --WHERE c.email = @customerEmail
  269. END
  270. ELSE IF @flag='checkpin'
  271. BEGIN
  272. DECLARE @TXN_PIN VARCHAR(30)
  273. IF NOT EXISTS(SELECT 'X' FROM customerMaster WITH (NOLOCK)
  274. WHERE username=@customerEmail and ISNULL(onlineUser, 'N')='Y')
  275. BEGIN
  276. SELECT @email=email,
  277. @customerPwd=customerPassword,
  278. @isActive=isactive,
  279. @onlineUser=onlineuser,
  280. @isLocked=isLocked,
  281. @ccountry=country,
  282. @customerStatus=customerStatus,
  283. @lastLoginDate=lastLoginTs,
  284. @loginAttempt = ISNULL(invalidAttemptPinCount, 0),
  285. @TXN_PIN = txnPin
  286. FROM customerMaster WITH (NOLOCK)
  287. WHERE username=@customerEmail and ISNULL(onlineUser, 'N')='Y'
  288. END
  289. ELSE
  290. BEGIN
  291. SELECT @email=email,
  292. @customerPwd=customerPassword,
  293. @isActive=isactive,
  294. @onlineUser=onlineuser,
  295. @isLocked=isLocked,
  296. @ccountry=country,
  297. @customerStatus=customerStatus,
  298. @lastLoginDate=lastLoginTs,
  299. @loginAttempt = ISNULL(invalidAttemptPinCount, 0),
  300. @TXN_PIN = txnPin
  301. FROM customerMaster WITH (NOLOCK)
  302. WHERE username=@customerEmail and ISNULL(onlineUser, 'N')='Y'
  303. END
  304. IF (ISNULL(@password, '') = ISNULL(@TXN_PIN, '-1'))
  305. BEGIN
  306. UPDATE customerMaster SET
  307. invalidAttemptPinCount = 0
  308. WHERE username = @customerEmail and ISNULL(onlineUser, 'N')='Y'
  309. SELECT 0 errorCode, 'Success' msg, @customerEmail id
  310. RETURN;
  311. END
  312. SELECT TOP 1 @attemptsCount = loginAttemptCount FROM passwordFormat WITH(NOLOCK)
  313. IF (ISNULL(@isLocked, 'N') IN ('B', 'Y')) OR ((@loginAttempt - @attemptsCount) = -1)
  314. BEGIN
  315. SELECT 18 errorCode, 'Too many wrong attempts, please contact JME Support!' mes, @customerEmail id
  316. EXEC proc_applicationLogs
  317. @flag='login',
  318. @logType='Send Transaction',
  319. @createdBy = @customerEmail,
  320. @Reason= 'Reason = Too many wrong attempts sending transaaction.'
  321. RETURN
  322. END
  323. IF (ISNULL(@password, '') <> ISNULL(@TXN_PIN, '-1'))
  324. BEGIN
  325. SET @UserInfoDetail = 'Reason = Incorrect PIN .-:::-' + @UserInfoDetail
  326. SET @loginAttempt = @loginAttempt + 1
  327. UPDATE customerMaster SET invalidAttemptPinCount = @loginAttempt, isLocked = CASE WHEN @loginAttempt > @attemptsCount THEN 'B' ELSE 'N' END
  328. WHERE username = @customerEmail and ISNULL(onlineUser, 'N')='Y'
  329. SET @InvalidReason = CASE WHEN @loginAttempt > @attemptsCount THEN 'Number of invalid PIN attempts exceeded!' ELSE 'Invalid PIN' END
  330. SET @InvalidMsg = 'Send txn Failed - Invalid PIN, you have ' + CAST((@attemptsCount - @loginAttempt) AS VARCHAR) + ' Attempts Left'
  331. SELECT 1 errorCode, @InvalidMsg mes, @customerEmail id
  332. EXEC proc_applicationLogs
  333. @flag='login',
  334. @logType='Send Transaction',
  335. @createdBy = @customerEmail,
  336. @Reason= 'Reason = wrong transaction PIN.'
  337. RETURN
  338. END
  339. END
  340. ELSE IF @flag='checkpass'
  341. BEGIN
  342. IF NOT EXISTS(SELECT 'X' FROM customerMaster WITH (NOLOCK)
  343. WHERE username=@customerEmail and ISNULL(onlineUser, 'N')='Y')
  344. BEGIN
  345. SELECT @email=email,
  346. @customerPwd=customerPassword,
  347. @isActive=isactive,
  348. @onlineUser=onlineuser,
  349. @isLocked=isLocked,
  350. @ccountry=country,
  351. @customerStatus=customerStatus,
  352. @lastLoginDate=lastLoginTs,
  353. @loginAttempt = ISNULL(invalidAttemptCount, 0),
  354. @TXN_PIN = txnPin
  355. FROM customerMaster WITH (NOLOCK)
  356. WHERE username=@customerEmail and ISNULL(onlineUser, 'N')='Y'
  357. END
  358. ELSE
  359. BEGIN
  360. SELECT @email=email,
  361. @customerPwd=customerPassword,
  362. @isActive=isactive,
  363. @onlineUser=onlineuser,
  364. @isLocked=isLocked,
  365. @ccountry=country,
  366. @customerStatus=customerStatus,
  367. @lastLoginDate=lastLoginTs,
  368. @loginAttempt = ISNULL(invalidAttemptCount, 0),
  369. @TXN_PIN = txnPin
  370. FROM customerMaster WITH (NOLOCK)
  371. WHERE username=@customerEmail and ISNULL(onlineUser, 'N')='Y'
  372. END
  373. IF (@customerPwd = dbo.FNAEncryptString(@password))
  374. BEGIN
  375. UPDATE customerMaster SET
  376. invalidAttemptCount = 0
  377. WHERE username = @customerEmail and ISNULL(onlineUser, 'N')='Y'
  378. SELECT 0 errorCode, 'Success' msg, @customerEmail id
  379. RETURN;
  380. END
  381. SELECT TOP 1 @attemptsCount = loginAttemptCount FROM passwordFormat WITH(NOLOCK)
  382. IF (ISNULL(@isLocked, 'N') IN ('B', 'Y')) OR ((@loginAttempt - @attemptsCount) = -1)
  383. BEGIN
  384. SELECT 9 errorCode, 'Too many wrong attempts, please contact GME Support!' mes, @customerEmail id
  385. EXEC proc_applicationLogs
  386. @flag='login',
  387. @logType='Send Transaction',
  388. @createdBy = @customerEmail,
  389. @Reason= 'Reason = Too many wrong attempts sending transaaction.'
  390. RETURN
  391. END
  392. IF (@customerPwd <> dbo.FNAEncryptString(@password))
  393. BEGIN
  394. SET @UserInfoDetail = 'Reason = Incorrect password .-:::-' + @UserInfoDetail
  395. SET @loginAttempt = @loginAttempt + 1
  396. UPDATE customerMaster SET invalidAttemptCount = @loginAttempt, isLocked = CASE WHEN @loginAttempt > @attemptsCount THEN 'B' ELSE 'N' END
  397. WHERE email = @customerEmail and ISNULL(onlineUser, 'N')='Y'
  398. SET @InvalidReason = CASE WHEN @loginAttempt > @attemptsCount THEN 'Number of invalid password attempts exceeded!' ELSE 'Invalid Password' END
  399. SET @InvalidMsg = 'Login Failed - Invalid Password, you have ' + CAST((@attemptsCount - @loginAttempt) AS VARCHAR) + ' Attempts Left'
  400. SELECT 1 errorCode, @InvalidMsg mes, @customerEmail id
  401. EXEC proc_applicationLogs
  402. @flag='login',
  403. @logType='Send Transaction',
  404. @createdBy = @customerEmail,
  405. @Reason= 'Reason = wrong transaction password.'
  406. RETURN
  407. END
  408. END
  409. END TRY
  410. BEGIN CATCH
  411. IF @@TRANCOUNT > 0
  412. ROLLBACK TRANSACTION
  413. DECLARE @errorMessage VARCHAR(MAX)
  414. SET @errorMessage = ERROR_MESSAGE()
  415. EXEC proc_errorHandler 1, @errorMessage,NULL
  416. END CATCH