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.

908 lines
52 KiB

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