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.

935 lines
54 KiB

11 months ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
9 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[mobile_proc_userLogin] Script Date: 3/29/2024 3:32:56 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROCEDURE [dbo].[mobile_proc_userLogin] @flag VARCHAR(30)
  9. ,@userName VARCHAR(100) = NULL
  10. ,@Password VARCHAR(100) = NULL
  11. ,@Imei VARCHAR(256) = NULL --Imei Number/UUID or Android id of Mobile
  12. ,@accessCode VARCHAR(MAX) = NULL -- access token used in every request
  13. ,@scope VARCHAR(50) = NULL --for mobile applicatin, @scope='mobile_app'
  14. ,@clientId VARCHAR(200) = NULL --basic header key
  15. ,@fcmid VARCHAR(250) = NULL
  16. ,@customerId VARCHAR(100) = NULL
  17. ,@ip VARCHAR(100) = NULL
  18. ,@isBiometricLogin VARCHAR(5) = NULL
  19. ,@biometricLoginType VARCHAR(20) = NULL
  20. ,@deviceType VARCHAR(100) = NULL
  21. ,@accessToken VARCHAR(MAX) = NULL -- access token for Biometric
  22. ,@residenceType VARCHAR(20) = NULL
  23. AS
  24. BEGIN TRY
  25. ----------------------------------------
  26. --@fcmid varchar(250), add @IP param
  27. --#182 - @isBiometricLogin VARCHAR(5), @biometricLoginType VARCHAR(20) , modifications in @flag='l'
  28. -- @isbiometricEnabled
  29. -- #225 - flag = l, check accessCode and status for biometric login
  30. -- add new param @accessToken for Biometric
  31. --select column [mobile_userRegistration].isForcePassChange
  32. --#101 , #361 - Mobile changes for multi lingual
  33. --#101 -set biometric as empty for '5' ErrorCode
  34. --No email OTP verification was prompt for existing customer which was activate over the counter.
  35. --#665 Remove JME online from Branch list
  36. --add for trustdoc @residenceType
  37. ----------------------------------------
  38. SET NOCOUNT ON;
  39. SET XACT_ABORT ON;
  40. DECLARE @UserData VARCHAR(500)
  41. ,@UserInfoDetail VARCHAR(MAX)
  42. ,@AccessCodeExpiresAfter INT = 5 --Minutes
  43. ,@email VARCHAR(100)
  44. ,@mobile VARCHAR(100)
  45. ,@customerPwd VARCHAR(50)
  46. ,@isActive CHAR(1)
  47. ,@isEmailVerified BIT
  48. ,@approvedDate DATETIME
  49. ,@isBiometricEnabled VARCHAR(10)
  50. --,@customerStatus VARCHAR(5)
  51. ----------------------- Local variables declaration ###STARTS------------------------
  52. DECLARE @_imei VARCHAR(256)
  53. ,@_otpUsed BIT
  54. ,@_scope VARCHAR(50)
  55. ,@_isDeleted CHAR(1)
  56. ,@_errorMsg VARCHAR(MAX)
  57. ,@_isExists BIT = 0
  58. ,@_Otp VARCHAR(50)
  59. ,@_accessCode VARCHAR(MAX)
  60. ,@_accessCodeExpiry DATETIME
  61. ,@_errorCode VARCHAR(20)
  62. ,@_lastLoggedInDevice VARCHAR(200)
  63. ,@previousAccessCode VARCHAR(MAX)
  64. ----------------------- Local variables declaration ###ENDS------------------------
  65. -- Check This Customer Infoagree State
  66. IF @flag = 'check-agree'
  67. BEGIN
  68. IF EXISTS (
  69. SELECT TOP 1 'X'
  70. FROM CustomerMasterTemp(NOLOCK)
  71. WHERE username = @userName
  72. AND ISNULL(agreeYn, '0') = '0'
  73. )
  74. BEGIN
  75. SELECT 0 ErrorCode
  76. ,'Get PDF List Success About Agree infomation' Msg
  77. ,NULL Id
  78. ,rowId
  79. ,PdfName
  80. ,AgreePdfPath
  81. FROM customerAgreeDocumentTbl(NOLOCK)
  82. WHERE targetObj = 'STAGING'
  83. RETURN
  84. END
  85. ELSE IF EXISTS (
  86. SELECT TOP 1 'X'
  87. FROM CustomerMaster(NOLOCK)
  88. WHERE email = @userName
  89. AND ISNULL(agreeYn, '0') = '0'
  90. )
  91. BEGIN
  92. SELECT 0 ErrorCode
  93. ,'Get PDF List Success About Agree infomation' Msg
  94. ,NULL Id
  95. ,rowId
  96. ,PdfName
  97. ,AgreePdfPath
  98. FROM customerAgreeDocumentTbl(NOLOCK)
  99. WHERE targetObj = 'STAGING'
  100. RETURN
  101. END
  102. ELSE
  103. BEGIN
  104. SELECT 1 ErrorCode
  105. ,'Invaild user.. Check user value ' Msg
  106. ,NULL Id
  107. END
  108. END
  109. ELSE IF @flag = 'l' -- login to system(done)
  110. BEGIN
  111. IF ISNULL(@username, '') = ''
  112. BEGIN
  113. SELECT '1' ErrorCode
  114. ,'User Id not defined.' Msg
  115. ,NULL ID
  116. RETURN
  117. END
  118. --IF EXISTS(SELECT * FROM customerMaster WHERE email = @userName AND ISNULL(mobileUser,'N') = 'N')
  119. --BEGIN
  120. -- SELECT '20' errorCode
  121. -- ,'Your JME account is disabled. Contact JME support.' msg
  122. -- ,@username id
  123. -- SET @UserInfoDetail = 'Reason = Login fails, Your mobile login is disabled. Please, contact your administrator.'
  124. -- EXEC proc_applicationLogs @flag = 'login'
  125. -- ,@logType = 'Login fails'
  126. -- ,@createdBy = @userName
  127. -- ,@Reason = 'Mobile login is disabled '
  128. -- ,@UserData = @UserData
  129. -- ,@fieldValue = @UserInfoDetail
  130. -- RETURN
  131. --END
  132. SELECT @scope = dbo.mobile_FNAGetApplicationScope(@clientId)
  133. IF ISNULL(@scope, '') <> 'mobile_app'
  134. BEGIN
  135. SELECT '2' ErrorCode
  136. ,'Application scope is not valid for this user.' Msg
  137. ,NULL ID
  138. RETURN
  139. END
  140. SET @UserData = 'User: ' + @username + ' ,Password: ' + @Password + ' ,User Type:Mobile User' + ' ,Device Info: ' + @imei + ' ,IsBiometricLogin: ' + @isBiometricLogin + ' ,BiometricTypeLogin: ' + @biometricLoginType + ' ,DeviceType: ' + @deviceType + ' ,AccessCode: ' + ISNULL(@accessCode, '') + ' ,AccessToken: ' + ISNULL(@accessToken, '')
  141. DECLARE @isReferred BIT = 0,@existingCustomer INT,@createdFrom VARCHAR(50)
  142. --IF EXISTS (
  143. -- SELECT TOP 1 'x'
  144. -- FROM referralmaster(NOLOCK)
  145. -- WHERE email = @userName
  146. -- OR mobile = @userName
  147. -- )
  148. -- SET @isReferred = 1
  149. --SELECT * FROM customerMaster WHERE email = @userName
  150. SELECT @_lastLoggedInDevice = lastLoggedInDevice
  151. ,@_accessCodeExpiry = accessCodeExpiry
  152. ,@_accessCode = accessCode
  153. FROM dbo.mobile_userRegistration(NOLOCK)
  154. WHERE username = @userName
  155. SELECT
  156. @existingCustomer= ISNULL(isexistingcustomer,0),
  157. @customerPwd=customerPassword
  158. ,@createdFrom=createdFrom
  159. FROM customerMaster WITH (NOLOCK)
  160. WHERE ISNULL(username,email)=@userName --and ISNULL(onlineUser, 'N')='Y'
  161. --IF @_lastLoggedInDevice = @Imei AND @_accessCodeExpiry > GETDATE()
  162. --BEGIN
  163. -- SET @accessCode=@_accessCode
  164. -- UPDATE mobile_userRegistration SET
  165. -- accessCodeExpiry = DATEADD(MINUTE,@AccessCodeExpiresAfter,GETDATE()) --adding validity of access token for 20 minutes.
  166. -- FROM dbo.mobile_userRegistration(NOLOCK) ur
  167. -- WHERE ur.username = @userName --END
  168. --ELSE
  169. DECLARE @JmeclientId VARCHAR(50)
  170. SELECT @JmeclientId = DBO.DECRYPTDB(clientId)
  171. FROM KFTC_GME_MASTER(NOLOCK)
  172. BEGIN
  173. BEGIN TRANSACTION
  174. IF @ResidenceType='0'
  175. SET @ResidenceType = NULL
  176. ELSE IF @ResidenceType='RESIDENCE' -- JAPANESE
  177. SET @ResidenceType = 'RESIDENT' /*ANDROID*/
  178. UPDATE mobile_userRegistration
  179. SET accessCode = @accessCode
  180. ,accessCodeExpiry = DATEADD(MINUTE, @AccessCodeExpiresAfter, GETDATE()) --adding validity of access token for 20 minutes.
  181. ,IMEI = @Imei
  182. ,lastLoggedInDevice = getdate()
  183. ,deviceId = ISNULL(@fcmid, deviceId)
  184. ,ipAddress = @ip
  185. ,BiometricLoginType = @biometricLoginType
  186. --,IsBiometricLogin = @isBiometricLogin
  187. ,DeviceType = @deviceType
  188. ,modifiedDate=GETDATE()
  189. ,ResidenceType=CASE WHEN @ResidenceType IS NOT NULL THEN @ResidenceType WHEN @ResidenceType='0' THEN ResidenceType ELSE ResidenceType END
  190. FROM dbo.mobile_userRegistration(NOLOCK)
  191. WHERE username = @userName
  192. IF @@TRANCOUNT > 0
  193. COMMIT TRANSACTION
  194. END
  195. DELETE T
  196. FROM customerMaster(NOLOCK) c
  197. INNER JOIN CustomerMasterTemp t ON c.username = t.username
  198. AND C.username = @userName
  199. DECLARE @redirectTo VARCHAR(100) = 'EYKC';
  200. IF( @existingCustomer=1 and (@customerPwd IS NULL OR @customerPwd=''))
  201. BEGIN
  202. SELECT '1' ErrorCode
  203. ,'Login Failed. Please click forgot Password to set new password.' Msg
  204. ,NULL
  205. RETURN
  206. END
  207. IF( @createdFrom='C' and (@customerPwd IS NULL OR @customerPwd=''))
  208. BEGIN
  209. SELECT '1' ErrorCode
  210. ,'Login Failed. Please click forgot Password to set new password.' Msg
  211. ,NULL
  212. RETURN
  213. END
  214. IF EXISTS (
  215. SELECT TOP 1 'X'
  216. FROM customerMasterTemp cm(NOLOCK)
  217. WHERE cm.username = @userName
  218. AND cm.customerPassword = dbo.FNAEncryptString(@Password)
  219. )
  220. OR (
  221. EXISTS (
  222. SELECT TOP 1 'X'
  223. FROM customerMasterTemp cm(NOLOCK)
  224. INNER JOIN MobileToken mt(NOLOCK) ON cm.email = mt.userName
  225. WHERE cm.username = @userName
  226. AND @isBiometricLogin = 'TRUE'
  227. AND mt.token = @accessToken
  228. AND mt.activeStatus = 'Y'
  229. )
  230. )
  231. BEGIN
  232. SELECT '0' ErrorCode
  233. ,'a' scope
  234. ,@userName userId
  235. ,cust.customerId SenderId
  236. ,ISNULL(cust.firstName, '') firstName
  237. -- ,ISNULL(cust.middleName,'') middleName
  238. -- ,ISNULL(cust.lastName1,'') lastName
  239. -- ,ISNULL(cust.nickName,'') nickName
  240. ,ISNULL(cust.email, '') email
  241. ,ISNULL(cust.customerEmail, '') customerEmail
  242. ,ISNULL(cust.mobile, '') phone
  243. -- ,cust.idType AS idType
  244. --,cust.idNumber AS idNumber
  245. ,cm.countryCode AS countryCode
  246. -- ,CAST(ISNULL(cust.bonusPoint,0) AS DECIMAL) rewardPoint
  247. ,CASE
  248. WHEN ISNULL(cust.isActive, 'Y') = 'Y'
  249. THEN 1
  250. ELSE 0
  251. END active
  252. ,kyc = 0
  253. ,CASE
  254. WHEN ISNULL(cust.verifiedDate, '') <> ''
  255. THEN 1
  256. ELSE 0
  257. END verified
  258. ,ISNULL(cust.walletAccountNo, '') walletNumber
  259. ,0 availableBalance
  260. ,'Fast Remit Bank' primaryBankName
  261. -- ,'' primaryBankAccount
  262. ,@accessCode accessCode
  263. ,DATEDIFF(SS, GETDATE(), ur.accessCodeExpiry) expiresIn
  264. -- ,ISNULL(dpUrl,'') dpUrl
  265. -- ,ISNULL(ur.cmRegistrationId,'') cmRegistrationId
  266. ,'' country
  267. ,ISNULL(cust.city, '') city
  268. ,ISNULL(cust.[address], '') [address]
  269. -- ,ISNULL(cust.state2,'') [province]
  270. ,'' [provinceId]
  271. -- ,@isReferred isReferred
  272. ,'' sourceId
  273. ,yearlyLimit = 0
  274. ,'0' AS pennyTestStatus
  275. ,gmeClientId = @JmeclientId
  276. ,redirectTo = @redirectTo
  277. ,cust.customerType
  278. ,ISNULL(ur.ResidenceType,'FOREIGNER') ResidenceType
  279. ,isExistingCustomer = ISNULL(isExistingCustomer, 1)
  280. ,IsBiometricLogin = ISNULL(IsBiometricLogin, 0)
  281. ,BiometricLoginType = ISNULL(BiometricLoginType, '')
  282. --,@customerStatus= ISNULL(customerStatus,'')
  283. ,CASE ur.isForcePassChange
  284. WHEN '1'
  285. THEN 'Y'
  286. ELSE 'N'
  287. END IsForcedPwdChange
  288. ,ISNULL(@accessToken, '') accessToken
  289. FROM (
  290. SELECT TOP 1 *
  291. FROM customerMasterTemp(NOLOCK) cust
  292. WHERE cust.username = @userName
  293. ) cust
  294. LEFT JOIN mobile_userRegistration(NOLOCK) ur ON cust.customerId = ur.customerId
  295. LEFT JOIN dbo.countryMaster(NOLOCK) AS CM ON cm.countryId = cust.nativeCountry
  296. --PRINT @ResidenceType
  297. --UPDATE customerMasterTemp SET idType =CASE WHEN @ResidenceType='FOREIGNER' THEN 11168
  298. --WHEN @ResidenceType IN('JAPANESE','RESIDENCE','RESIDENT') THEN 11079 ELSE 11168 END
  299. --WHERE username = @userName
  300. --WHERE cust.username=@userName
  301. EXEC proc_applicationLogs @flag = 'login'
  302. ,@logType = 'Login Success'
  303. ,@createdBy = @username
  304. ,@Reason = 'Login'
  305. ,@UserData = @UserData
  306. ,@fieldValue = @UserInfoDetail
  307. RETURN
  308. END
  309. IF UPPER(@isBiometricLogin) = 'TRUE'
  310. BEGIN
  311. SELECT @isbiometricEnabled = (
  312. SELECT ISNULL(isBiometricLogin, 0)
  313. FROM mobile_userRegistration
  314. WHERE username = @userName
  315. )
  316. IF @isbiometricEnabled = 0
  317. BEGIN
  318. SELECT '3' ErrorCode
  319. ,'Fingerprint login is not enabled. Please login using password.' Msg
  320. ,NULL ID
  321. RETURN
  322. END
  323. IF ISNULL(@accessToken, '') = ''
  324. BEGIN
  325. SELECT '4' ErrorCode
  326. ,'Access Token is required for Fingerprint login.' Msg
  327. ,NULL ID
  328. RETURN
  329. END
  330. IF NOT EXISTS (
  331. SELECT TOP 1 *
  332. FROM MobileToken(NOLOCK)
  333. WHERE userName = @userName
  334. AND token = @accessToken
  335. AND activeStatus = 'Y'
  336. )
  337. BEGIN
  338. UPDATE mobile_userRegistration SET isBiometricLogin=0,BiometricLoginType=null,DeviceType=null, modifiedDate=GETDATE(), modifiedby= @userName
  339. WHERE username = @userName
  340. SELECT '5' ErrorCode
  341. ,'Unauthorized Login for Fingerprint login. Please login using password.' Msg
  342. ,NULL
  343. RETURN
  344. END
  345. SELECT @email = email
  346. ,@mobile = cm.mobile
  347. ,@customerPwd = customerPassword
  348. ,@isActive = isactive
  349. ,@customerId = cm.customerId
  350. ,@approvedDate = cm.approvedDate
  351. FROM customerMaster(NOLOCK) cm
  352. WHERE cm.username = @userName
  353. -- AND ISNULL(cm.mobileUser,'Y') = 'Y'
  354. END
  355. ELSE
  356. BEGIN
  357. SELECT @email = email
  358. ,@mobile = cm.mobile
  359. ,@customerPwd = customerPassword
  360. ,@isActive = isactive
  361. ,@customerId = cm.customerId
  362. ,@approvedDate = cm.approvedDate
  363. --,@customerStatus=ISNULL(customerStatus,'')
  364. FROM customerMaster(NOLOCK) cm
  365. WHERE cm.username = @userName
  366. --OR cm.mobile=@userName ## NOT MOBILE LOGIN NOT APPLICABLE
  367. AND cm.customerPassword = dbo.FNAEncryptString(@Password)
  368. -- AND ISNULL(cm.mobileUser,'Y')='Y'
  369. END
  370. IF @customerId IS NULL --OR @activeStatus = 'N'
  371. BEGIN
  372. SELECT '6' errorCode,'The username/password do not match.' msg
  373. SET @UserInfoDetail = 'Reason = Incorrect username.'
  374. EXEC dbo.proc_applicationLogs @flag = 'login'
  375. ,@logType = 'Login fails'
  376. ,@createdBy = @username
  377. ,@Reason = 'Invalid Username'
  378. ,@UserData = @UserData
  379. ,@fieldValue = @UserInfoDetail
  380. RETURN
  381. END
  382. DECLARE @isMobileLoginEnabled VARCHAR(1)
  383. IF EXISTS(SELECT * FROM customerMasterTemp WHERE email = @userName AND ISNULL(mobileUser,'Y') = 'N')
  384. BEGIN
  385. SELECT @isMobileLoginEnabled = 'N'
  386. END
  387. ELSE
  388. SELECT @isMobileLoginEnabled = 'Y'
  389. IF EXISTS(SELECT * FROM customerMaster WHERE email = @userName AND ISNULL(mobileUser,'Y') = 'N')
  390. BEGIN
  391. SELECT @isMobileLoginEnabled = 'N'
  392. END
  393. ELSE
  394. SELECT @isMobileLoginEnabled = 'Y'
  395. IF @isMobileLoginEnabled = 'N'
  396. BEGIN
  397. SELECT '20' errorCode
  398. ,'Your IME account is disabled. Contact IME London support.' msg
  399. ,@username id
  400. SET @UserInfoDetail = 'Reason = Login fails, Your mobile login is disabled. Please, contact your administrator.'
  401. EXEC proc_applicationLogs @flag = 'login'
  402. ,@logType = 'Login fails'
  403. ,@createdBy = @userName
  404. ,@Reason = 'Mobile login is disabled '
  405. ,@UserData = @UserData
  406. ,@fieldValue = @UserInfoDetail
  407. RETURN
  408. END
  409. BEGIN TRANSACTION
  410. IF NOT EXISTS (
  411. SELECT TOP 1 'X'
  412. FROM mobile_userRegistration ur(NOLOCK)
  413. WHERE ur.username = @userName
  414. )
  415. BEGIN
  416. INSERT INTO mobile_userRegistration (
  417. customerId
  418. ,username
  419. ,OTP
  420. ,OTP_Used
  421. ,createdDate
  422. ,IMEI
  423. ,clientId
  424. ,deviceId
  425. ,ipAddress
  426. ,BiometricLoginType
  427. ,IsBiometricLogin
  428. ,DeviceType
  429. ,ResidenceType
  430. )
  431. SELECT @customerId
  432. ,@userName
  433. ,0
  434. ,0
  435. ,GETDATE()
  436. ,@Imei
  437. ,@clientId
  438. ,@fcmid
  439. ,@ip
  440. ,@biometricLoginType
  441. ,@isBiometricLogin
  442. ,@deviceType
  443. ,@residenceType
  444. UPDATE cm
  445. SET cm.isEmailVerified = 1
  446. FROM dbo.customerMaster cm
  447. WHERE cm.customerId = @customerId AND ISNULL(cm.customerStatus,'')<>'OTC'
  448. END
  449. IF @@TRANCOUNT > 0
  450. COMMIT TRANSACTION
  451. DECLARE @attemptsCount INT
  452. SELECT TOP 1 @attemptsCount = loginAttemptCount
  453. FROM passwordFormat WITH (NOLOCK)
  454. IF (ISNULL(@isActive, 'Y') = 'N')
  455. BEGIN
  456. SELECT '7' errorCode
  457. ,'Your account is Inactive. Please, contact IME London Support Team.' msg
  458. ,@userName id
  459. SET @UserInfoDetail = 'Reason = Login fails, Your account is Inactive. Please, contact your administrator.'
  460. EXEC proc_applicationLogs @flag = 'login'
  461. ,@logType = 'Login fails'
  462. ,@createdBy = @userName
  463. ,@Reason = 'User is not active '
  464. ,@UserData = @UserData
  465. ,@fieldValue = @UserInfoDetail
  466. RETURN
  467. END
  468. UPDATE customerMaster
  469. SET lastLoginTs = GETDATE()
  470. --,idType =CASE WHEN @ResidenceType='FOREIGNER' THEN 11168 WHEN @ResidenceType='JAPANESE' THEN 11079 ELSE idType END
  471. WHERE customerId = @customerId
  472. DECLARE @yearlyLimit VARCHAR(100) = ''
  473. DECLARE @totalSend MONEY
  474. ,@totalSendText VARCHAR(200)
  475. ,@YearStart DATE
  476. ,@YearEnd DATETIME
  477. SELECT @YearStart = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0)
  478. ,@YearEnd = DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, - 1) + ' 23:59:59'
  479. SELECT @totalSend = SUM(R.cAmt)
  480. FROM REMITTRAN R(NOLOCK)
  481. INNER JOIN TRANSENDERS T(NOLOCK) ON T.TRANID = R.ID
  482. AND T.CUSTOMERID = @customerId
  483. AND R.TRANSTATUS <> 'Cancel'
  484. AND R.approvedDate BETWEEN @YearStart
  485. AND @YearEnd
  486. SELECT @yearlyLimit = amount
  487. FROM dbo.csDetail CD(NOLOCK)
  488. INNER JOIN csMaster CM(NOLOCK) ON CM.csMasterId = CD.csMasterId
  489. AND CD.period = 365
  490. AND CD.condition = 4600
  491. AND ISNULL(CD.isActive, 'Y') = 'Y'
  492. AND ISNULL(CD.isDeleted, 'N') = 'N'
  493. AND ISNULL(CD.isEnable, 'Y') = 'Y'
  494. AND ISNULL(CM.isActive, 'Y') = 'Y'
  495. AND ISNULL(CM.isDeleted, 'N') = 'N'
  496. SET @yearlyLimit = (@yearlyLimit - ISNULL(@totalSend, 0))
  497. DECLARE @hasPennyTestDone VARCHAR(1) = '1'
  498. --IF EXISTS (
  499. -- SELECT TOP 1 'x'
  500. -- FROM dbo.customerMaster(NOLOCK)
  501. -- WHERE approvedDate < '2018-12-19'
  502. -- AND customerId = @customerId
  503. -- )
  504. --BEGIN
  505. -- SET @hasPennyTestDone = '2'
  506. --END
  507. SELECT '0' ErrorCode
  508. ,@scope scope
  509. ,@userName userId
  510. ,cust.customerId SenderId
  511. ,ISNULL(cust.firstName, '') firstName
  512. -- ,ISNULL(cust.middleName,'') middleName
  513. -- ,ISNULL(cust.lastName1,'') lastName
  514. -- ,'' nickName
  515. ,ISNULL(cust.email, '') email
  516. ,ISNULL(cust.customerEmail, '') customerEmail
  517. ,ISNULL(cust.mobile, '') phone
  518. -- ,cust.idType AS idType
  519. --,cust.idNumber AS idNumber
  520. ,cm1.countryCode AS countryCode
  521. ,CAST(ISNULL(cust.bonusPoint, 0) AS DECIMAL) rewardPoint
  522. ,CASE
  523. WHEN ISNULL(cust.isActive, 'Y') = 'Y'
  524. THEN 1
  525. ELSE 0
  526. END active
  527. ,ISNULL(HasDeclare, 0) kyc
  528. ,CASE
  529. WHEN ISNULL(isExistingCustomer, 1) = 0
  530. THEN CASE
  531. WHEN cust.ApprovedDate IS NOT NULL
  532. THEN 1
  533. ELSE 0
  534. END
  535. ELSE CASE
  536. WHEN mobileVerifiedDate IS NOT NULL
  537. THEN 1
  538. ELSE 0
  539. END
  540. END verified
  541. ,ISNULL(cust.walletAccountNo, '') walletNumber
  542. ,CAST([dbo].FNAGetCustomerACBal(@email) AS DECIMAL) availableBalance
  543. --,ISNULL(bl.BankName,'') primaryBankName
  544. ,primaryBankName = 'Fast Remit Bank' --CASE WHEN cust.customerType='11048' THEN 'Mutual savings bank' ELSE 'Kwangju Bank (034)' END
  545. -- ,'' AS primaryBankAccount
  546. ,@accessCode accessCode
  547. ,DATEDIFF(SS, GETDATE(), ur.accessCodeExpiry) expiresIn
  548. -- ,'' dpUrl
  549. -- ,ISNULL(ur.cmRegistrationId,'') cmRegistrationId
  550. ,ISNULL(co.countryName, '') country
  551. ,ISNULL(cust.city, '') city
  552. ,ISNULL(cust.[address], '') [address]
  553. -- ,ISNULL(cust.state2,'') [province]
  554. ,ISNULL(cm.cityId, '') [provinceId]
  555. -- ,@isReferred isReferred
  556. ,ISNULL(sdv.valueId, '') sourceId
  557. ,yearlyLimit = @yearlyLimit
  558. ,PennyTestStatus = @hasPennyTestDone -----0 not started, 1 requested , 2 completed
  559. ,gmeClientId = @JmeclientId
  560. ,redirectTo = @redirectTo
  561. ,cust.customerType
  562. ,ISNULL(ur.ResidenceType,'FOREIGNER') ResidenceType
  563. ,isExistingCustomer = ISNULL(isExistingCustomer, 1)
  564. ,IsBiometricLogin = ISNULL(IsBiometricLogin, 0)
  565. ,BiometricLoginType = ISNULL(BiometricLoginType, '')
  566. ,CASE ur.isForcePassChange
  567. WHEN '1'
  568. THEN 'Y'
  569. ELSE 'N'
  570. END IsForcedPwdChange
  571. ,ISNULL(@accessToken, '') accessToken
  572. FROM (
  573. SELECT TOP 1 *
  574. FROM customerMaster(NOLOCK) cust
  575. WHERE cust.customerId = @customerId
  576. ) cust
  577. LEFT JOIN dbo.countryMaster AS CM1 ON cm1.countryId = cust.nativeCountry
  578. LEFT JOIN mobile_userRegistration(NOLOCK) ur ON cust.customerId = ur.customerId
  579. LEFT JOIN dbo.vwBankLists(NOLOCK) bl ON cust.bankName = bl.bankCode
  580. LEFT JOIN countryMaster co(NOLOCK) ON cust.country = co.countryId
  581. LEFT JOIN staticDatavalue sdv(NOLOCK) ON cust.sourceOfFund = sdv.detailTitle
  582. AND ISNULL(sdv.IS_DELETE, 'N') = 'N'
  583. LEFT JOIN dbo.CityMaster cm(NOLOCK) ON cust.state2 = cm.cityName
  584. --WHERE cust.customerId=@customerId AND ISNULL(sdv.IS_DELETE,'N')='N'
  585. EXEC proc_applicationLogs @flag = 'login'
  586. ,@logType = 'Login Success'
  587. ,@createdBy = @username
  588. ,@Reason = 'Login'
  589. ,@UserData = @UserData
  590. ,@fieldValue = @UserInfoDetail
  591. RETURN
  592. END
  593. ELSE IF @flag = 'chk-access-code' --validating access code(done)
  594. BEGIN
  595. --SELECT
  596. -- @_accessCodeExpiry=l.accessCodeExpiry
  597. -- ,@username=ISNULL(l.username,cust.email)
  598. -- ,@_scope=ISNULL(a.scope,'')
  599. -- ,@_lastLoggedInDevice=ISNULL(cust.lastLoggedInDevice,'')
  600. -- ,@_imei =ISNULL(cust.lastLoggedInDevice,'')
  601. --FROM customermasterTemp(NOLOCK) cust
  602. --INNER JOIN customermaster(NOLOCK) main ON main.customerId=cust.customerMasterId
  603. --LEFT JOIN mobile_userRegistration(NOLOCK) l ON cust.customerId=l.customerId
  604. --INNER JOIN mobile_GmeApiClientRegistration a(NOLOCK) ON a.clientId=l.clientId
  605. --WHERE l.accessCode=@accessCode
  606. SELECT @_accessCodeExpiry = MUR.accessCodeExpiry
  607. ,@username = mur.username
  608. ,@_scope = ISNULL(a.scope, '')
  609. ,@_lastLoggedInDevice = mur.lastLoggedInDevice
  610. ,@_imei = mur.IMEI
  611. ,@customerId = mur.rowId
  612. FROM dbo.mobile_userRegistration AS MUR(NOLOCK)
  613. INNER JOIN mobile_GmeApiClientRegistration a(NOLOCK) ON a.clientId = MUR.clientId
  614. AND MUR.accessCode = @accessCode
  615. AND (
  616. mur.IMEI = @Imei
  617. OR mur.lastLoggedInDevice = @Imei
  618. )
  619. --PRINT @_accessCodeExpiry
  620. --IF NOT EXISTS(SELECT 'x' FROM dbo.mobile_userRegistration AS MUR WHERE MUR.accessCode=@accessCode AND MUR.IMEI=@Imei)
  621. --BEGIN
  622. -- SELECT '2' errorCode, 'Access code expired..' Msg ,NULL ID
  623. -- RETURN
  624. --END
  625. --IF NOT EXISTS(SELECT 'x' FROM dbo.mobile_userRegistration AS MUR WHERE MUR.accessCode=@accessCode AND MUR.lastLoggedInDevice=@Imei)
  626. --BEGIN
  627. -- SELECT '2' errorCode, 'Access code expired..' Msg ,NULL ID
  628. -- RETURN
  629. --END
  630. IF ISNULL(@username, '') = ''
  631. AND ISNULL(@_lastLoggedInDevice, '') = @imei
  632. BEGIN
  633. SELECT '8' errorCode
  634. ,'Access code expired..' Msg
  635. ,NULL ID
  636. RETURN
  637. END
  638. IF ISNULL(@username, '') = ''
  639. AND ISNULL(@_lastLoggedInDevice, '') <> @imei
  640. BEGIN
  641. SELECT '9' errorCode
  642. ,'Access code expired..' Msg
  643. ,NULL ID
  644. RETURN
  645. END
  646. IF (@_accessCodeExpiry < GETDATE())
  647. BEGIN
  648. SELECT '10' errorCode
  649. ,'It seems like you are using old access code. Please use newly generated access code.' Msg
  650. ,NULL ID
  651. RETURN
  652. END
  653. ------------- ### Check if the user trying to validate access-code exists or not ###STARTS------------
  654. IF @username IS NULL
  655. BEGIN
  656. SELECT @_errorMsg = 'User with contact Info ' + @username + ' doesnot exists. If you are a new user, then sign up and proceed further.'
  657. SELECT '1' ErrorCode
  658. ,@_errorMsg Msg
  659. ,NULL ID
  660. RETURN
  661. END
  662. ------------- ### Check if the user trying to validate access-code exists or not ###ENDS------------
  663. IF @_lastLoggedInDevice <> @Imei
  664. BEGIN
  665. SELECT '11' errorCode
  666. ,'You are logged in from another device.' Msg
  667. ,NULL ID
  668. RETURN
  669. END
  670. ELSE IF ISNULL(@_scope, '') <> 'mobile_app'
  671. BEGIN
  672. SELECT '12' ErrorCode
  673. ,'Application scope is not valid for this user.' Msg
  674. ,NULL ID
  675. RETURN
  676. END
  677. UPDATE mobile_userRegistration
  678. SET accessCodeExpiry = DATEADD(MINUTE, @AccessCodeExpiresAfter, GETDATE()) --expiry time for access code(token) increased to 20 minutes.
  679. WHERE rowId = @customerId
  680. SELECT '0' ErrorCode
  681. ,'Success' Msg
  682. ,@_scope ID
  683. RETURN
  684. END
  685. ELSE IF @flag = 's-accesscode' --validating accessCode for "Get user by access code"
  686. BEGIN
  687. IF @scope <> 'social_comp'
  688. BEGIN
  689. SELECT '13' ErrorCode
  690. ,'Application scope is not valid for this user.' Msg
  691. ,NULL ID
  692. RETURN
  693. END
  694. DECLARE @user VARCHAR(100);
  695. SELECT @email = cm.email
  696. ,@mobile = cm.mobile
  697. ,@isEmailVerified = cm.isEmailVerified
  698. ,@customerId = cm.customerId
  699. FROM dbo.customerMaster(NOLOCK) cm
  700. INNER JOIN dbo.mobile_userRegistration(NOLOCK) ur ON cm.customerId = ur.customerId
  701. AND ur.accessCode = @accessCode
  702. IF @email IS NOT NULL
  703. AND @isEmailVerified = 1
  704. BEGIN
  705. SET @user = @email
  706. END
  707. ELSE
  708. BEGIN
  709. SET @user = @mobile
  710. END
  711. SELECT @_imei = l.imei
  712. ,@_accessCodeExpiry = l.accessCodeExpiry
  713. ,@username = @user
  714. FROM customermaster cust(NOLOCK)
  715. INNER JOIN mobile_userRegistration l(NOLOCK) ON cust.customerId = l.customerId
  716. AND l.accessCode = @accessCode
  717. IF DATEDIFF(MINUTE, GETDATE(), @_accessCodeExpiry) > 0
  718. BEGIN
  719. SELECT '0' ErrorCode
  720. ,@userName userId
  721. ,ISNULL(cust.firstName, '') firstName
  722. ,ISNULL(cust.middleName, '') middleName
  723. ,ISNULL(cust.lastName1, '') lastName
  724. ,ISNULL(cm.countryName, '') nativeCountry
  725. ,'' nickName
  726. ,userRoles = ''
  727. ,'' dpUrl
  728. ,ISNULL(ur.cmRegistrationId, '') cmRegistrationId
  729. ,ISNULL(ur.IMEI, '') uuid
  730. FROM (
  731. SELECT TOP 1 *
  732. FROM customerMaster(NOLOCK) cust
  733. WHERE cust.customerId = @customerId
  734. ) cust
  735. LEFT JOIN mobile_userRegistration ur(NOLOCK) ON cust.customerId = ur.customerId
  736. LEFT JOIN dbo.countryMaster cm(NOLOCK) ON cust.nativeCountry = cm.countryId
  737. --WHERE cust.customerId=@customerId
  738. --WHERE cust.email=@userName OR cust.mobile=@userName
  739. RETURN
  740. END
  741. ELSE IF DATEDIFF(MINUTE, GETDATE(), @_accessCodeExpiry) <= 0
  742. BEGIN
  743. SELECT '14' ErrorCode
  744. ,'Access code expired.' Msg
  745. ,NULL ID
  746. RETURN
  747. END
  748. ELSE
  749. BEGIN
  750. SELECT '15' ErrorCode
  751. ,'Access code does not match.' Msg
  752. ,NULL ID
  753. RETURN
  754. END
  755. END
  756. ELSE IF @flag = 'ckeck-guid'
  757. BEGIN
  758. IF EXISTS (
  759. SELECT TOP 1 'A'
  760. FROM dbo.mobile_userRegistration(NOLOCK)
  761. WHERE accessCode IS NULL
  762. AND username = @userName
  763. )
  764. BEGIN
  765. UPDATE dbo.mobile_userRegistration
  766. SET accessCode = @accessCode
  767. WHERE accessCode IS NULL
  768. AND username = @userName
  769. END
  770. IF EXISTS (
  771. SELECT TOP 1 'A'
  772. FROM dbo.mobile_userRegistration(NOLOCK)
  773. WHERE accessCode = @accessCode
  774. AND username = @userName
  775. )
  776. BEGIN
  777. SELECT '0' ErrorCode
  778. ,'The access code is valid and is from trusted customer.' Msg
  779. ,NULL Id
  780. RETURN
  781. END
  782. BEGIN
  783. SELECT '1' ErrorCode
  784. ,'No such access code found in system. Invalid username and customer is not trusted.' Msg
  785. ,NULL Id
  786. RETURN
  787. END
  788. END
  789. ELSE IF @flag = 'get-device'
  790. BEGIN
  791. SELECT deviceId
  792. FROM mobile_userRegistration(NOLOCK)
  793. WHERE customerId = @customerId
  794. RETURN
  795. END
  796. ELSE IF @flag = 'agentDetail'
  797. BEGIN
  798. SELECT agentId
  799. ,agentName
  800. ,agentState
  801. ,agentCity
  802. ,agentAddress
  803. ,agentZip
  804. ,agentPhone1
  805. FROM AGENTMASTER(NOLOCK)
  806. WHERE PARENTID = '393877'
  807. and agentid<>'394395'
  808. AND ACTASBRANCH = 'Y'
  809. RETURN
  810. END
  811. END TRY
  812. BEGIN CATCH
  813. IF @@TRANCOUNT > 0
  814. ROLLBACK TRANSACTION
  815. DECLARE @errorMessage VARCHAR(MAX)
  816. SET @errorMessage = ERROR_MESSAGE()
  817. SELECT '1' ErrorCode
  818. ,@errorMessage Msg
  819. ,NULL ID
  820. END CATCH