public async Task <object> Login([FromBody] LoginDto model) { var result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, false, false); if (result.Succeeded) { var appUser = _userManager.Users.SingleOrDefault(r => r.UserName == model.Username); var claims = await _userManager.GetClaimsAsync(appUser); var service = new UserRepositoryService(ConnString); var userEntry = await service.GetUseryByUserName(model.Username); var response = new GenericResponse <LoginResponse>() { IsSuccess = true, Message = "Signed in successfully.", ResponseCode = 200 }; var res = new LoginResponse() { Jwt = await GenerateJwtToken(model.Username, appUser, claims) }; res.PopulateCode(userEntry[0].IPAddress, userEntry[0].IsNewAccount, model.DeviceIP); response.Result = res; return(Ok(response)); } throw new ApplicationException("INVALID_LOGIN_ATTEMPT"); }
public GitStorage(GitStorageSettings settings, GitHubService gitHubService, AdminRepositoryService adminRepositoryService, UserRepositoryService userRepositoryService, SystemService system) { System = system; if (settings.Local) { Root = settings.Root; } this.gitHubService = gitHubService; this.userRepositoryService = userRepositoryService; this.adminRepositoryService = adminRepositoryService; }
public async Task <IActionResult> Get(int id) { var service = new UserRepositoryService(connString); var result = await service.GetUserById(id); var response = new GenericResponse <UserDetails>() { IsSuccess = true, Message = "Data fetched successfully.", ResponseCode = 200, Result = result }; return(Ok(response)); }
public async Task <IActionResult> Put(int id, UserUpdateModel model) { var service = new UserRepositoryService(connString); await service.UpdateUser(model, id); var response = new GenericResponse <string>() { IsSuccess = true, Message = "User updated successfully.", ResponseCode = 200, Result = "Success" }; return(Ok(response)); }
public async Task <IActionResult> Put(int id, UserRegistrationUpdateModel model) { var service = new UserRepositoryService(connString); await service.TerminateUserRegistration(id, "user1", model.EndDate); var response = new GenericResponse <string>() { IsSuccess = true, Message = "User Registrtion Updated successfully.", ResponseCode = 200, Result = "Success" }; return(Ok(response)); }
public async Task <IActionResult> DeleteUser(int Id) { var service = new UserRepositoryService(connString); var username = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub"); await service.DeleteUser(Id, username); var response = new GenericResponse <string>() { IsSuccess = true, Message = "User deleted successfully.", ResponseCode = 200, Result = "Success" }; return(Ok(response)); }
public async Task <IActionResult> UserSearch(UserSearchByName model) { var service = new UserRepositoryService(connString); var result = await service.GetUserSearchByName(model.InstituteId, model.Name); var response = new GenericResponse <List <UserDetails> >() { IsSuccess = true, Message = "Data fetched successfully.", ResponseCode = 200, Result = result }; return(Ok(response)); }
public async Task <IActionResult> Create(UserRegistrationModel model) { var service = new UserRepositoryService(connString); await service.CreateUserRegistration(model.UserId, model.InstituteId, "User1", model.StartDate, model.ClassId, model.SectionId); var response = new GenericResponse <string>() { IsSuccess = true, Message = "User Registrtion Created successfully.", ResponseCode = 200, Result = "Success" }; return(Ok(response)); }
public async Task <IActionResult> CreateUser(UserModel model) { var service = new UserRepositoryService(connString); var serviceEntity = new EntityRepositoryService(connString); var user = new IdentityUser { UserName = model.Username, Email = model.EmailId }; var result = await _userManager.CreateAsync(user, model.Password); var userType = await serviceEntity.GetAllEntityById(model.UserTypeId); var response = new GenericResponse <string>(); if (result.Succeeded) { await _userManager.AddClaimAsync(user, new Claim("rId", userType[0].EntityName)); await service.CreateUser(model); response = new GenericResponse <string>() { IsSuccess = true, Message = "User created successfully.", ResponseCode = 200, Result = "Success" }; } else { response = new GenericResponse <string>() { IsSuccess = false, Message = "Failure", ErrorMessage = result.Errors.Select(a => a.Description).ToList(), ResponseCode = 500, Result = "Failure" }; } return(Ok(response)); }
public async Task <IActionResult> UpdateUserLogin(UpdateUserLoginModel model) { var username = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub"); //string value = Request.Headers["Authorization"]; //value = value.Remove(0, 7); //var jwtHandler = new JwtSecurityTokenHandler(); //var token = jwtHandler.ReadJwtToken(value); //var usernameClaim = token.Claims.Where(a=>a.Type=="sub").FirstOrDefault(); var service = new UserRepositoryService(connString); await service.UpdateUserLogin(username, model.IsNewAccount, model.IPAddress); var response = new GenericResponse <string>() { IsSuccess = true, Message = "User updated successfully.", ResponseCode = 200, Result = "Success" }; return(Ok(response)); }
public async Task <IActionResult> CreateAmazonAccount(int id) { var actor = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub"); var service = new UserRepositoryService(connString); var instituteAmazonAccInfo = await service.GetInstituteAmazonAccountDetail(id); var amazons3Service = new AmazonS3Service(); var accname = instituteAmazonAccInfo.UserName.ToLower(); await amazons3Service.CreateFolder(instituteAmazonAccInfo.BucketName, accname, instituteAmazonAccInfo.AccessKey, instituteAmazonAccInfo.SecretKey); var amazoniamService = new AmazonIAMService(); var iamacc = accname + Guid.NewGuid().ToString().ToLower(); var path = "/" + instituteAmazonAccInfo.BucketName + "/" + instituteAmazonAccInfo.UserName.ToLower() + "/"; var amazonaccount = await amazoniamService.CreateIAMUser(path, iamacc); var model = new UserAmazonAccount() { AccessKey = amazonaccount.AccessKey, Actor = actor, BucketName = instituteAmazonAccInfo.BucketName, BucketPath = "/" + instituteAmazonAccInfo.UserName.ToLower(), IamUsername = iamacc, SecretKey = amazonaccount.SecurityKey, UserId = instituteAmazonAccInfo.UserId }; await service.CreateUserAmazonAccount(model); var response = new GenericResponse <string>() { IsSuccess = true, Message = "Amazon account created successfully.", ResponseCode = 200, Result = "Success" }; return(Ok(response)); }
public async Task <IActionResult> Get(string username) { var result = new List <UserDTO>(); var service = new UserRepositoryService(connString); if (string.IsNullOrEmpty(username)) { result = await service.GetAllUser(); } else { result = await service.GetUseryByUserName(username); } var response = new GenericResponse <List <UserDTO> >() { IsSuccess = true, Message = "Data fetched successfully.", ResponseCode = 200, Result = result }; return(Ok(response)); }
public async Task <IActionResult> Get(int?instituteId) { var result = new List <UserRegistrationDTO>(); var service = new UserRepositoryService(connString); if (instituteId.HasValue) { result = await service.GetAllUserRegistrationByInstituteId(instituteId.Value); } else { result = await service.GetAllUserRegistration(); } var response = new GenericResponse <List <UserRegistrationDTO> >() { IsSuccess = true, Message = "Data fetched successfully.", ResponseCode = 200, Result = result }; return(Ok(response)); }