public async Task <ActionResult> PostUser([FromBody] UserLogRequest form) { if (!_authService.IsAuthenticate(UserLog.GroupId)) { return(Unauthorized()); } var apiType = Utility.GetTypeFromUrl(Request.Path.Value); if (apiType == LogType.Empty) { return(NotFound()); } else { var userLog = new UserLog() { EntityId = form.target_id.ToString(), Metadata = form.meta_data, AuthorId = form.user_id.ToString(), ProjectType = form.project_type, Description = form.description, RegionId = form.region_id.ToString(), IncidentId = form.incident_id.ToString(), ResolveProblemId = form.resolve_problem_id.ToString(), Timestamp = Utility.GetTimeNow() }; return(await Post <UserLog>(userLog, apiType)); } }
public async Task <bool> LogInAsync(UserLogRequest logModel) { bool isSuccessful = false; UserAuthData response = GetAuth(logModel); if (response != null) { isSuccessful = await LogIn(response); } return(isSuccessful); }
public async Task <ActionResult <SuccessResponse> > Login(UserLogRequest logModel) { int code = 200; BaseResponse response = null; try { User model = _userService.GetByEmail(logModel.Email); if (model != null && model.UserStatusId != 1) { return(StatusCode(401, new ErrorResponse("Please confirm your account."))); } else { bool isLoggedIn = await _userService.LogInAsync(logModel); if (isLoggedIn) { response = new ItemResponse <string>() { Item = logModel.Email }; return(Ok200(response)); } else { return(StatusCode(401, new ErrorResponse("The information provided does not match our records. Please correct the information entered and try again."))); } } } catch (Exception ex) { code = 500; base.Logger.LogError(ex.ToString()); response = new ErrorResponse($"Generic Error: {ex.Message}"); } return(StatusCode(code, response)); }
public UserAuthData GetAuth(UserLogRequest logModel) { string passwordFromDb = ""; UserAuthData authModel = null; Dictionary <int, List <Role> > userRoles = null; _dataProvider.ExecuteCmd("dbo.Users_Select_AuthData", inputParamMapper : delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@Email", logModel.Email); }, singleRecordMapper : delegate(IDataReader reader, short set) { int index; switch (set) { case 0: index = 0; int roleId = reader.GetSafeInt32(index++); string roleName = reader.GetSafeString(index++); int userId = reader.GetSafeInt32(index++); if (userRoles == null) { userRoles = new Dictionary <int, List <Role> >(); } Role role = new Role() { Id = roleId, Name = roleName }; if (userRoles.ContainsKey(userId)) { userRoles[userId].Add(role); } else { userRoles.Add(userId, new List <Role> { role }); } break; case 1: passwordFromDb = reader.GetSafeString(2); bool isValidCredentials = BCrypt.BCryptHelper.CheckPassword(logModel.Password, passwordFromDb); if (isValidCredentials) { authModel = new UserAuthData(); index = 0; authModel.Id = reader.GetSafeInt32(index++); authModel.Email = reader.GetSafeString(index++); authModel.Password = reader.GetSafeString(index++); authModel.UserStatusId = reader.GetSafeInt32(index++); if (userRoles.ContainsKey(authModel.Id)) { authModel.Roles = userRoles[authModel.Id]; } } break; } } ); return(authModel); }