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.

691 lines
47 KiB

  1. USE [FastMoneyPro_Remit]
  2. GO
  3. /****** Object: StoredProcedure [dbo].[proc_applicationIntlLogin] Script Date: 4/4/2024 6:10:56 PM ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER PROC [dbo].[proc_applicationIntlLogin]
  9. @flag VARCHAR(50) = NULL
  10. ,@userId VARCHAR(10) = NULL
  11. ,@user VARCHAR(30) = NULL
  12. ,@userName VARCHAR(30) = NULL
  13. ,@agentCode VARCHAR(20) = NULL
  14. ,@pwd VARCHAR(255) = NULL
  15. ,@UserInfoDetail VARCHAR(MAX) = NULL
  16. ,@employeeId VARCHAR(10) = NULL
  17. ,@ipAddress VARCHAR(100) = NULL
  18. ,@dcLogindcUserName VARCHAR(MAX) = NULL
  19. ,@dcSerialNumber VARCHAR(100) = NULL
  20. ,@dcUserName VARCHAR(100) = NULL
  21. ,@LOGIN_COUNTRY NVARCHAR(50) = NULL
  22. ,@LOGIN_COUNTRY_CODE NVARCHAR(30) = NULL
  23. ,@LOGIN_CITY NVARCHAR(200) = NULL
  24. ,@LOGIN_REGION NVARCHAR(200) = NULL
  25. ,@LOGIN_LAT NVARCHAR(20) = NULL
  26. ,@LOGIN_LONG NVARCHAR(20) = NULL
  27. ,@LOGIN_TIMEZONE NVARCHAR(30) = NULL
  28. ,@LOGIN_ZIPCODDE NVARCHAR(30) = NULL
  29. ,@OTP_USED VARCHAR(10) = NULL
  30. ,@IS_OTP_ENABLED CHAR(1) = NULL
  31. ,@selectedAgentId INT = NULL
  32. AS
  33. SET NOCOUNT ON;
  34. SET XACT_ABORT ON;
  35. DECLARE
  36. @UserData VARCHAR(200)
  37. ,@parentAgentId VARCHAR(200)
  38. ,@agentType VARCHAR(20)
  39. ,@actAsBranch VARCHAR(20)
  40. ,@lastPwdChangedOn DATETIME
  41. ,@forceChangePwd CHAR(1)
  42. ,@pwdChangeDays VARCHAR(20)
  43. ,@msg VARCHAR(2000)
  44. ,@pwdChangeWarningDays VARCHAR(5)
  45. ,@agentId INT
  46. DECLARE
  47. @countryId INT
  48. ,@country VARCHAR(50)
  49. ,@branch INT
  50. ,@branchName VARCHAR(100)
  51. ,@agent INT
  52. ,@superAgent INT
  53. ,@superAgentName VARCHAR(100)
  54. ,@mapCodeInt VARCHAR(8)
  55. ,@parentMapCodeInt VARCHAR(8)
  56. ,@agentName VARCHAR(250)
  57. ,@settlingAgent INT
  58. ,@parentId INT
  59. ,@mapCodeDom VARCHAR(8)
  60. ,@isHeadOffice CHAR(1)
  61. ,@superAgentId VARCHAR(10)
  62. DECLARE
  63. @agentActiveStatus CHAR(1)
  64. ,@branchActiveStatus CHAR(1)
  65. ,@loginUserName VARCHAR(100)
  66. ,@loginPwd VARCHAR(100)
  67. ,@userActive CHAR(1)
  68. ,@loginUserAgtCode VARCHAR(100)
  69. ,@loginUserAgtId VARCHAR(100)
  70. ,@empId VARCHAR(100)
  71. ,@isLocked CHAR(1)
  72. ,@isDeleted CHAR(1)
  73. ,@loginTime TIME
  74. ,@logoutTime TIME
  75. ,@startDate DATETIME
  76. ,@endDate DATETIME
  77. ,@lastLoginTs DATETIME
  78. ,@lockUserDays INT
  79. ,@userDcSerialNumber VARCHAR(100)
  80. ,@agentLocation INT
  81. ,@agentGrp INT
  82. ,@agentEmail VARCHAR(100)
  83. ,@agentPhone VARCHAR(100)
  84. ,@invalidPwdCount TINYINT
  85. --## Intl Agent Login
  86. IF @flag = 'lfai'
  87. BEGIN
  88. DECLARE @rowId BIGINT, @selectedAgentName VARCHAR(150)
  89. IF @selectedAgentId IS NOT NULL
  90. SELECT @selectedAgentName = AGENTNAME FROM AGENTMASTER (NOLOCK) WHERE AGENTID = @selectedAgentId
  91. SET @UserData ='User:' + @userName + ', UserCode:' + CAST(ISNULL(@employeeId, 'OTP ENABLED') AS VARCHAR(20)) + ', SelectedAgent:' + ISNULL(@selectedAgentName, '')
  92. SELECT
  93. @userId = userId
  94. ,@loginUserName = userName
  95. ,@userActive = ISNULL(au.isActive, 'N')
  96. ,@loginPwd = pwd
  97. ,@loginUserAgtCode = au.agentCode
  98. ,@loginUserAgtId = au.agentId
  99. ,@empId = employeeId
  100. ,@isLocked = ISNULL(isLocked, 'N')
  101. ,@loginTime = loginTime
  102. ,@logoutTime = logoutTime
  103. ,@lastLoginTs = lastLoginTs
  104. ,@agentType = am.agentType
  105. ,@actAsBranch = am.actAsBranch
  106. ,@agentId = am.agentId
  107. ,@agentActiveStatus = ISNULL(am.isActive, 'N')
  108. ,@userDcSerialNumber= dcSerialNumber
  109. ,@agentLocation = am.agentLocation
  110. ,@agentGrp = am.agentGrp
  111. ,@forceChangePwd = au.forceChangePwd
  112. ,@invalidPwdCount = ISNULL(AU.wrongPwdCount, 0)
  113. FROM applicationUsers au WITH(NOLOCK)
  114. INNER JOIN agentMaster am WITH(NOLOCK) ON au.agentId = am.agentId
  115. WHERE userName = @userName and ISNULL(au.isDeleted, 'N') = 'N'
  116. --AND AM.AGENTCOUNTRY <> 'NEPAL'
  117. IF ISNULL(@invalidPwdCount, 0) > 3
  118. BEGIN
  119. UPDATE applicationUsers SET
  120. wrongPwdCount = ISNULL(wrongPwdCount, 0) + 1
  121. WHERE userId = @userId
  122. SELECT 1 errorCode, 'You are locked due to Continious Invalid login attempts. Please, contact your administrator' mes, @userName id, 0 rowId
  123. RETURN;
  124. END
  125. SELECT
  126. @startDate = startDate
  127. ,@endDate = endDate
  128. FROM userLockDetail WITH(NOLOCK)
  129. WHERE userId = @userId
  130. AND ISNULL(isDeleted,'N') = 'N'
  131. IF @userId IS NULL
  132. BEGIN
  133. SET @UserInfoDetail = 'Reason = Login fails, Incorrect user name.-:::-' + @UserInfoDetail
  134. EXEC proc_applicationLogs
  135. @flag = 'login',
  136. @logType = 'Login fails',
  137. @createdBy = @userName,
  138. @Reason = 'Invalid Username',
  139. @UserData = @UserData,
  140. @fieldValue = @UserInfoDetail,
  141. @agentId = @agentId,
  142. @IP = @ipAddress,
  143. @dcSerialNumber = @dcSerialNumber,
  144. @dcUserName = @dcUserName ,
  145. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  146. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  147. @LOGIN_CITY = @LOGIN_CITY,
  148. @LOGIN_REGION = @LOGIN_REGION,
  149. @LOGIN_LAT = @LOGIN_LAT,
  150. @LOGIN_LONG = @LOGIN_LONG,
  151. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  152. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  153. @OTP_USED = @OTP_USED,
  154. @rowId = @rowId OUT
  155. SELECT 11 errorCode, 'Login fails, Incorrect user name or password.' mes, @userName id, @rowId rowId
  156. RETURN
  157. END
  158. --IF @LOGIN_COUNTRY <> 'Nepal' --AND @userName <> 'raman'
  159. --BEGIN
  160. -- SELECT 1 errorCode, 'System is currently down, due to system maintainance.' mes, @userName id, @rowId rowId
  161. -- RETURN
  162. --END
  163. -- ## Except IME EXCHANGE COUNTER- TIA
  164. --IF @userDcSerialNumber IS NOT NULL AND @userDcSerialNumber <> @dcSerialNumber AND @agentId <> '9943'
  165. --BEGIN
  166. -- SELECT 1 errorCode, 'Login fails, Not a valid Digital Certificate for this user.' mes, @userName id
  167. -- SET @UserInfoDetail = 'Reason = Login fails, Not a valid Digital Certificate for this user.-:::-'+@UserInfoDetail
  168. -- EXEC proc_applicationLogs
  169. -- @flag = 'login',
  170. -- @logType = 'Login fails',
  171. -- @createdBy = @userName,
  172. -- @Reason = 'Not a valid Digital Certificate for this user',
  173. -- @UserData = @UserData,
  174. -- @fieldValue = @UserInfoDetail,
  175. -- @agentId = @agentId,
  176. -- @IP = @ipAddress,
  177. -- @dcSerialNumber = @dcSerialNumber,
  178. -- @dcUserName = @dcUserName
  179. -- RETURN
  180. --END
  181. --IF @dcSerialNumber IS NOT NULL AND @dcSerialNumber not like '%00-05-00-00%'
  182. --BEGIN
  183. -- SELECT 1 errorCode, 'Login fails, Not a valid IME CERTIFICATE, Please Use Valid IME Certificate.' mes, @userName id
  184. -- SET @UserInfoDetail = 'Reason = Login fails, Not a valid IME CERTIFICATE-:::-' + @UserInfoDetail
  185. -- EXEC proc_applicationLogs
  186. -- @flag = 'login',
  187. -- @logType = 'Login fails',
  188. -- @createdBy = @userName,
  189. -- @Reason = 'Not a valid IME CERTIFICATE',
  190. -- @UserData = @UserData,
  191. -- @fieldValue = @UserInfoDetail,
  192. -- @agentId = @agentId,
  193. -- @IP = @ipAddress,
  194. -- @dcSerialNumber = @dcSerialNumber,
  195. -- @dcUserName = @dcUserName
  196. -- RETURN
  197. --END
  198. IF @userActive = 'N'
  199. BEGIN
  200. SET @UserInfoDetail = 'Reason = User has not been approved.-:::-' + @UserInfoDetail
  201. EXEC proc_applicationLogs
  202. @flag = 'login',
  203. @logType = 'Login fails',
  204. @createdBy = @userName,
  205. @Reason = 'User is not active',
  206. @UserData = @UserData,
  207. @fieldValue = @UserInfoDetail,
  208. @agentId = @agentId,
  209. @IP = @ipAddress,
  210. @dcSerialNumber = @dcSerialNumber,
  211. @dcUserName = @dcUserName ,
  212. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  213. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  214. @LOGIN_CITY = @LOGIN_CITY,
  215. @LOGIN_REGION = @LOGIN_REGION,
  216. @LOGIN_LAT = @LOGIN_LAT,
  217. @LOGIN_LONG = @LOGIN_LONG,
  218. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  219. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  220. @OTP_USED = @OTP_USED,
  221. @rowId = @rowId OUT
  222. SELECT 1 errorCode, 'User is not active.' mes, @userName id, @rowId rowId
  223. RETURN
  224. END
  225. IF @agentActiveStatus = 'N'
  226. BEGIN
  227. SET @UserInfoDetail = 'Reason = Branch is not active.-:::-' + @UserInfoDetail
  228. EXEC proc_applicationLogs
  229. @flag = 'login',
  230. @logType = 'Login fails',
  231. @createdBy = @userName,
  232. @Reason = 'Branch is not active',
  233. @UserData = @UserData,
  234. @fieldValue = @UserInfoDetail,
  235. @agentId = @agentId,
  236. @IP = @ipAddress,
  237. @dcSerialNumber = @dcSerialNumber,
  238. @dcUserName = @dcUserName ,
  239. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  240. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  241. @LOGIN_CITY = @LOGIN_CITY,
  242. @LOGIN_REGION = @LOGIN_REGION,
  243. @LOGIN_LAT = @LOGIN_LAT,
  244. @LOGIN_LONG = @LOGIN_LONG,
  245. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  246. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  247. @OTP_USED = @OTP_USED,
  248. @rowId = @rowId OUT
  249. SELECT 1 errorCode, 'Your account is blocked.' mes, @userName id, @rowId rowId
  250. RETURN
  251. END
  252. DECLARE @attemptsCount INT
  253. SELECT TOP 1 @attemptsCount = loginAttemptCount, @lockUserDays = ISNULL(lockUserDays,30) FROM passwordFormat WITH(NOLOCK)
  254. IF (@loginPwd <> ISNULL(dbo.FNAEncryptString(@pwd), ''))
  255. BEGIN
  256. UPDATE applicationUsers SET
  257. wrongPwdCount = ISNULL(wrongPwdCount, 0) + 1
  258. WHERE userId = @userId
  259. SET @UserInfoDetail = 'Reason = Login fails, Incorrect password.-:::-'+@UserInfoDetail
  260. EXEC proc_applicationLogs
  261. @flag = 'login',
  262. @logType = 'Login fails',
  263. @createdBy = @userName,
  264. @Reason = 'Incorrect password',
  265. @UserData = @UserData,
  266. @fieldValue = @UserInfoDetail,
  267. @agentId = @agentId,
  268. @IP = @ipAddress,
  269. @dcSerialNumber = @dcSerialNumber,
  270. @dcUserName = @dcUserName ,
  271. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  272. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  273. @LOGIN_CITY = @LOGIN_CITY,
  274. @LOGIN_REGION = @LOGIN_REGION,
  275. @LOGIN_LAT = @LOGIN_LAT,
  276. @LOGIN_LONG = @LOGIN_LONG,
  277. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  278. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  279. @OTP_USED = @OTP_USED,
  280. @rowId = @rowId OUT
  281. SET @invalidPwdCount += 1
  282. IF @invalidPwdCount < 3
  283. BEGIN
  284. SELECT 2 errorCode, 'Login fails, Incorrect user name or password, attempts left ' + CAST((3 - @invalidPwdCount) AS VARCHAR) mes, @userName id, @attemptsCount ac, @rowId rowId
  285. RETURN
  286. END
  287. END
  288. IF ISNULL(@invalidPwdCount, 0) >= 3
  289. BEGIN
  290. UPDATE applicationUsers SET
  291. isLocked = 'Y'
  292. ,lastLoginTs = GETDATE()
  293. ,wrongPwdCount = ISNULL(wrongPwdCount, 0) + 1
  294. WHERE userId = @userId
  295. SET @UserInfoDetail = 'Reason = User Locked due to Invalid login attempts.-:::-' + @UserInfoDetail
  296. EXEC proc_applicationLogs
  297. @flag = 'login',
  298. @logType = 'Login fails',
  299. @createdBy = @userName,
  300. @Reason = 'User Locked due to Invalid login attempts.',
  301. @UserData = @UserData,
  302. @fieldValue = @UserInfoDetail,
  303. @agentId = @agentId,
  304. @IP = @ipAddress,
  305. @dcSerialNumber = @dcSerialNumber,
  306. @dcUserName = @dcUserName ,
  307. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  308. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  309. @LOGIN_CITY = @LOGIN_CITY,
  310. @LOGIN_REGION = @LOGIN_REGION,
  311. @LOGIN_LAT = @LOGIN_LAT,
  312. @LOGIN_LONG = @LOGIN_LONG,
  313. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  314. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  315. @OTP_USED = @OTP_USED,
  316. @rowId = @rowId OUT
  317. SELECT 1 errorCode, 'You are locked due to Continious Invalid login attempts. Please, contact your administrator' mes, @userName id, @rowId rowId
  318. INSERT INTO userLockHistory(username, lockReason, createdBy, createdDate)
  319. SELECT @userName, 'Your account has been locked due to Invalid login attempts', 'system', GETDATE()
  320. RETURN;
  321. END
  322. --IF (@loginUserAgtCode <> ISNULL(@agentCode, ''))
  323. --BEGIN
  324. -- SET @UserInfoDetail = 'Reason = Login fails, Incorrect AgentCode.-:::-' + @UserInfoDetail
  325. -- EXEC proc_applicationLogs
  326. -- @flag = 'login',
  327. -- @logType = 'Login fails',
  328. -- @createdBy = @userName,
  329. -- @Reason = 'Incorrect AgentCode',
  330. -- @UserData = @UserData,
  331. -- @fieldValue = @UserInfoDetail,
  332. -- @agentId = @agentId,
  333. -- @IP = @ipAddress,
  334. -- @dcSerialNumber = @dcSerialNumber,
  335. -- @dcUserName = @dcUserName ,
  336. -- @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  337. -- @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  338. -- @LOGIN_CITY = @LOGIN_CITY,
  339. -- @LOGIN_REGION = @LOGIN_REGION,
  340. -- @LOGIN_LAT = @LOGIN_LAT,
  341. -- @LOGIN_LONG = @LOGIN_LONG,
  342. -- @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  343. -- @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  344. -- @OTP_USED = @OTP_USED,
  345. -- @rowId = @rowId OUT
  346. -- SELECT 2 errorCode, 'Login fails, Incorrect user name or password.' mes, @userName id, @attemptsCount ac, @rowId rowId
  347. -- RETURN
  348. --END
  349. IF (@empId <> ISNULL(@employeeId, '')) AND ISNULL(@IS_OTP_ENABLED, 'N') = 'N'
  350. BEGIN
  351. SET @UserInfoDetail = 'Reason = Login fails, Incorrect userId.-:::-'+@UserInfoDetail
  352. EXEC proc_applicationLogs
  353. @flag = 'login',
  354. @logType = 'Login fails',
  355. @createdBy = @userName,
  356. @Reason = 'Incorrect userId',
  357. @UserData = @UserData,
  358. @fieldValue = @UserInfoDetail,
  359. @agentId = @agentId,
  360. @IP = @ipAddress,
  361. @dcSerialNumber = @dcSerialNumber,
  362. @dcUserName = @dcUserName ,
  363. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  364. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  365. @LOGIN_CITY = @LOGIN_CITY,
  366. @LOGIN_REGION = @LOGIN_REGION,
  367. @LOGIN_LAT = @LOGIN_LAT,
  368. @LOGIN_LONG = @LOGIN_LONG,
  369. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  370. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  371. @OTP_USED = @OTP_USED,
  372. @rowId = @rowId OUT
  373. SELECT 2 errorCode, 'Login fails, Incorrect user name or password.' mes, @userName id, @attemptsCount ac, @rowId rowId
  374. RETURN
  375. END
  376. IF(@isLocked = 'Y')
  377. BEGIN
  378. SET @UserInfoDetail = 'Reason = Your account has been locked. Please, contact your administrator.-:::-'+@UserInfoDetail
  379. EXEC proc_applicationLogs
  380. @flag = 'login',
  381. @logType = 'Login fails',
  382. @createdBy = @userName,
  383. @Reason = 'Your account has been locked',
  384. @UserData = @UserData,
  385. @fieldValue = @UserInfoDetail,
  386. @agentId = @agentId,
  387. @IP = @ipAddress,
  388. @dcSerialNumber = @dcSerialNumber,
  389. @dcUserName = @dcUserName ,
  390. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  391. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  392. @LOGIN_CITY = @LOGIN_CITY,
  393. @LOGIN_REGION = @LOGIN_REGION,
  394. @LOGIN_LAT = @LOGIN_LAT,
  395. @LOGIN_LONG = @LOGIN_LONG,
  396. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  397. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  398. @OTP_USED = @OTP_USED,
  399. @rowId = @rowId OUT
  400. SELECT 1 errorCode, 'Your account has been locked. Please, contact your administrator.' mes, @userName id, @rowId rowId
  401. RETURN;
  402. END
  403. --IF CAST(GETDATE() AS TIME) < @loginTime OR CAST(GETDATE() AS TIME) > @logoutTime
  404. --BEGIN
  405. -- SET @UserInfoDetail = 'Reason = You are not permitted to login at this time. Please, contact your administrator-:::-' + @UserInfoDetail
  406. -- EXEC proc_applicationLogs
  407. -- @flag = 'login',
  408. -- @logType = 'Login fails',
  409. -- @createdBy = @userName,
  410. -- @Reason = 'Not permitted to login at this time',
  411. -- @UserData = @UserData,
  412. -- @fieldValue = @UserInfoDetail,
  413. -- @agentId = @agentId,
  414. -- @IP = @ipAddress,
  415. -- @dcSerialNumber = @dcSerialNumber,
  416. -- @dcUserName = @dcUserName ,
  417. -- @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  418. -- @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  419. -- @LOGIN_CITY = @LOGIN_CITY,
  420. -- @LOGIN_REGION = @LOGIN_REGION,
  421. -- @LOGIN_LAT = @LOGIN_LAT,
  422. -- @LOGIN_LONG = @LOGIN_LONG,
  423. -- @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  424. -- @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  425. -- @OTP_USED = @OTP_USED,
  426. -- @rowId = @rowId OUT
  427. -- SELECT 1 errorCode, 'You are not permitted to login at this time. Please, contact your administrator.' mes, @userName id, @rowId rowId
  428. -- RETURN
  429. --END
  430. --IF (GETDATE() BETWEEN @startDate AND CONVERT(VARCHAR(20), @endDate,101) + ' 23:59:59')
  431. --BEGIN
  432. -- SET @UserInfoDetail = 'Reason = You are not permitted to login at this time. Please, contact your administrator-:::-'+@UserInfoDetail
  433. -- EXEC proc_applicationLogs
  434. -- @flag = 'login',
  435. -- @logType = 'Login fails',
  436. -- @createdBy = @userName,
  437. -- @Reason = 'Not permitted to login for this date',
  438. -- @UserData = @UserData,
  439. -- @fieldValue = @UserInfoDetail,
  440. -- @agentId = @agentId,
  441. -- @IP = @ipAddress,
  442. -- @dcSerialNumber = @dcSerialNumber,
  443. -- @dcUserName = @dcUserName ,
  444. -- @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  445. -- @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  446. -- @LOGIN_CITY = @LOGIN_CITY,
  447. -- @LOGIN_REGION = @LOGIN_REGION,
  448. -- @LOGIN_LAT = @LOGIN_LAT,
  449. -- @LOGIN_LONG = @LOGIN_LONG,
  450. -- @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  451. -- @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  452. -- @OTP_USED = @OTP_USED,
  453. -- @rowId = @rowId OUT
  454. -- SELECT 1 errorCode, 'You are not permitted to login for this date. Please, contact your administrator' mes, @userName id, @rowId rowId
  455. -- RETURN
  456. --END
  457. -- Last Login date check for Locking
  458. IF(DATEDIFF(DAY, @lastLoginTs, GETDATE()) >= @lockUserDays)
  459. BEGIN
  460. UPDATE applicationUsers SET
  461. isLocked = 'Y'
  462. ,lastLoginTs = GETDATE()
  463. WHERE userId = @userId
  464. SET @UserInfoDetail = 'Reason = You are locked this time. Please, contact your administrator.-:::-' + @UserInfoDetail
  465. EXEC proc_applicationLogs
  466. @flag = 'login',
  467. @logType = 'Login fails',
  468. @createdBy = @userName,
  469. @Reason = 'Not Login for fix period, now user is locked',
  470. @UserData = @UserData,
  471. @fieldValue = @UserInfoDetail,
  472. @agentId = @agentId,
  473. @IP = @ipAddress,
  474. @dcSerialNumber = @dcSerialNumber,
  475. @dcUserName = @dcUserName ,
  476. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  477. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  478. @LOGIN_CITY = @LOGIN_CITY,
  479. @LOGIN_REGION = @LOGIN_REGION,
  480. @LOGIN_LAT = @LOGIN_LAT,
  481. @LOGIN_LONG = @LOGIN_LONG,
  482. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  483. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  484. @OTP_USED = @OTP_USED,
  485. @rowId = @rowId OUT
  486. SELECT 1 errorCode, 'You are locked this time. Please, contact your administrator' mes, @userName id, @rowId rowId
  487. INSERT INTO userLockHistory(username, lockReason, createdBy, createdDate)
  488. SELECT @userName, 'Your account has been locked due to not login for fix period', 'system', GETDATE()
  489. RETURN;
  490. END
  491. UPDATE applicationUsers SET
  492. lastLoginTs = GETDATE()
  493. ,dcSerialNumber = ISNULL(dcSerialNumber, @dcSerialNumber)
  494. ,dcUserName = ISNULL(dcUserName, @dcUserName)
  495. WHERE [userName] = @userName
  496. SELECT
  497. @country = am.agentCountry
  498. ,@countryId = am.agentCountryId
  499. ,@branch = au.agentId
  500. ,@branchName = am.agentName
  501. ,@agentName = am.agentName
  502. ,@mapCodeInt = am.mapCodeInt
  503. ,@parentmapCodeInt = am.mapCodeInt
  504. ,@mapCodeDom = am.mapCodeDom
  505. ,@agentType = am.agentType
  506. ,@actAsBranch = actAsBranch
  507. ,@agent = CASE WHEN am.agentType = 2903 THEN au.agentId ELSE am.parentId END
  508. ,@superAgent = am.parentId
  509. ,@parentId = am.parentId
  510. ,@settlingAgent = CASE WHEN ISNULL(am.isSettlingAgent, 'N') = 'Y' THEN au.agentId ELSE NULL END
  511. ,@agentEmail = am.agentEmail1
  512. ,@agentPhone = am.agentPhone1
  513. FROM agentMaster am WITH(NOLOCK)
  514. INNER JOIN applicationUsers au WITH(NOLOCK) ON am.agentId = au.agentId
  515. WHERE au.userName = @userName
  516. --IF @country = 'Nepal'
  517. --BEGIN
  518. -- SET @UserInfoDetail = 'Reason = You are not permitted from International agent Login panel. Please, contact your administrator-:::-' + @UserInfoDetail
  519. -- EXEC proc_applicationLogs
  520. -- @flag = 'login',
  521. -- @logType = 'Login fails',
  522. -- @createdBy = @userName,
  523. -- @Reason = 'Not Login for fix period, now user is locked',
  524. -- @UserData = @UserData,
  525. -- @fieldValue = @UserInfoDetail,
  526. -- @agentId = @agentId,
  527. -- @IP = @ipAddress,
  528. -- @dcSerialNumber = @dcSerialNumber,
  529. -- @dcUserName = @dcUserName ,
  530. -- @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  531. -- @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  532. -- @LOGIN_CITY = @LOGIN_CITY,
  533. -- @LOGIN_REGION = @LOGIN_REGION,
  534. -- @LOGIN_LAT = @LOGIN_LAT,
  535. -- @LOGIN_LONG = @LOGIN_LONG,
  536. -- @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  537. -- @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  538. -- @OTP_USED = @OTP_USED,
  539. -- @rowId = @rowId OUT
  540. -- SELECT 1 errorCode, 'You are not permitted to login from International agent Login panel. Please, contact your administrator.' mes, @userName id, @rowId rowId
  541. -- RETURN
  542. --END
  543. IF(@agentType <> 2903)
  544. BEGIN
  545. SELECT
  546. TOP 1
  547. @agentName = agentName
  548. ,@parentMapCodeInt = mapCodeInt
  549. ,@superAgent = parentId
  550. FROM agentMaster WITH(NOLOCK) WHERE agentId = @agent
  551. END
  552. SELECT TOP 1 @superAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @superAgent
  553. IF @settlingAgent IS NULL
  554. SELECT @settlingAgent = agentId FROM agentMaster WITH(NOLOCK) WHERE agentId = @agent AND isSettlingAgent = 'Y'
  555. EXEC proc_applicationLogs
  556. @flag = 'login',
  557. @logType ='Login',
  558. @createdBy = @userName,
  559. @Reason = 'Agent Login',
  560. @UserData = @UserData,
  561. @fieldValue = @UserInfoDetail,
  562. @agentId = @agentId,
  563. @IP = @ipAddress,
  564. @dcSerialNumber = @dcSerialNumber,
  565. @dcUserName = @dcUserName ,
  566. @LOGIN_COUNTRY = @LOGIN_COUNTRY,
  567. @LOGIN_COUNTRY_CODE = @LOGIN_COUNTRY_CODE,
  568. @LOGIN_CITY = @LOGIN_CITY,
  569. @LOGIN_REGION = @LOGIN_REGION,
  570. @LOGIN_LAT = @LOGIN_LAT,
  571. @LOGIN_LONG = @LOGIN_LONG,
  572. @LOGIN_TIMEZONE = @LOGIN_TIMEZONE,
  573. @LOGIN_ZIPCODDE = @LOGIN_ZIPCODDE,
  574. @OTP_USED = @OTP_USED,
  575. @rowId = @rowId OUT
  576. UPDATE applicationUsers SET
  577. wrongPwdCount = 0
  578. WHERE userId = @userId
  579. SELECT
  580. TOP 1
  581. 0 errorCode
  582. ,'Login success.' mes
  583. , @rowId rowId
  584. ,@userName Id
  585. ,au.userAccessLevel
  586. ,au.sessionTimeOutPeriod
  587. ,au.UserID
  588. ,fullName = au.firstName + ISNULL(' ' + au.middleName, '') + ISNULL(' ' + au.lastName, '')
  589. ,parentId = ISNULL(@parentId, 0)
  590. ,agentType = ISNULL(@agentType, 2901)
  591. ,settlingAgent = ISNULL(@settlingAgent, 0)
  592. ,isActAsBranch = ISNULL(@actAsBranch, 'N')
  593. ,mapCodeInt = ISNULL(@mapCodeInt, '0000')
  594. ,parentMapCodeInt = ISNULL(@parentMapCodeInt, '0000')
  595. ,mapCodeDom = ISNULL(@mapCodeDom, '0000')
  596. ,country = @country
  597. ,countryId = @countryId
  598. ,branch = @branch
  599. ,branchName = @branchName
  600. ,agent = @agent
  601. ,agentName = @agentName
  602. ,superAgent = ISNULL(@superAgent, 0)
  603. ,superAgentName = ISNULL(@superAgentName, 0)
  604. ,au.lastLoginTs
  605. ,fromSendTrnTime = CASE WHEN x.globalOperationTimeEnable = 'Y' AND @settlingAgent <> 1249 THEN operationTimeFrom ELSE au.fromSendTrnTime END
  606. ,toSendTrnTime = CASE WHEN x.globalOperationTimeEnable = 'Y' AND @settlingAgent <> 1249 THEN operationTimeTo ELSE au.toSendTrnTime END
  607. ,fromPayTrnTime = CASE WHEN x.globalOperationTimeEnable = 'Y' AND @settlingAgent <> 1249 THEN operationTimeFrom ELSE au.fromPayTrnTime END
  608. ,toPayTrnTime = CASE WHEN x.globalOperationTimeEnable = 'Y' AND @settlingAgent <> 1249 THEN operationTimeTo ELSE au.toPayTrnTime END
  609. ,au.userType
  610. ,isHeadOffice = @isHeadOffice
  611. ,newBranchId = newBranchId
  612. ,agentLocation = @agentLocation
  613. ,agentGrp = @agentGrp
  614. ,agentEmail = @agentEmail
  615. ,agentPhone = @agentPhone
  616. ,isForcePwdChanged = au.forceChangePwd
  617. ,UserUniqueKey = S.USER_UNIQUE_CODE
  618. FROM applicationUsers au WITH(NOLOCK)
  619. LEFT JOIN passwordFormat x WITH(NOLOCK) ON 1 = 1
  620. LEFT JOIN TBL_USER_2FA_SETUP S(NOLOCK) ON S.[USER_ID] = au.UserID
  621. WHERE au.userName = @userName
  622. RETURN
  623. END