public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var userManager = context.OwinContext.GetUserManager <Business.User.UserManager>(); Contracts.User foundUser = await userManager.FindAsync(context.UserName, context.Password); if (foundUser == null) { context.Rejected(); context.SetError("The user name or password is incorrect."); //context.SetError("invalid_grant", "The user name or password is incorrect."); return; } var userRepo = new Data.Repository.UserRepository(); string deviceToken = context.OwinContext.Get <string>("device_token"); userRepo.SetDeviceToken(foundUser.Id, deviceToken); Business.User.User user = new Business.User.User(foundUser); ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType); oAuthIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id)); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Email, user.Email)); AuthenticationProperties properties = CreateProperties(user); AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); //context.Request.Context.Authentication.SignIn(cookiesIdentity); }
public static AuthenticationProperties CreateProperties(Business.User.User user) { IDictionary <string, string> data = new Dictionary <string, string> { { "userName", user.UserName }, { "userId", user.Id } }; return(new AuthenticationProperties(data)); }
public TransferBalanceOut TransferBalance(TransferBalanceIn input) { var output = new TransferBalanceOut() { result = Entities.Common.Result.Error }; var request = new Business.User.User(); var getUserInfoOut = request.GetUsers(new MethodParameters.User.GetUsersIn() { }).listUsers.FirstOrDefault(x => x.usrID == input.currentUser.usrID); var permissionRequest = new Business.Permission.Permission(); var validateAccesFunctionOut = permissionRequest.GetPermissionByRole(new MethodParameters.Permission.GetPermissionByRoleIn() { role = getUserInfoOut.usr_role }); if (validateAccesFunctionOut.result == Entities.Common.Result.Success && validateAccesFunctionOut.listPermissions.FirstOrDefault(x => x.pm_code == "06") != null) { var getUserOut = request.GetUser(new MethodParameters.User.GetUserIn() { usr_userName = input.usr_userNameOrigin }); if (getUserOut.result == Entities.Common.Result.Success && getUserOut.user.usr_balance >= input.valueTransfer) { var transferBalanceOut = request.TransferBalance(new MethodParameters.User.TransferBalanceIn() { usr_userNameOrigin = input.usr_userNameOrigin, usr_userNameDestiny = input.usr_userNameDestiny, valueTransfer = input.valueTransfer }); if (transferBalanceOut.result == Entities.Common.Result.Success) { output.message = "Transferencia realizada con exito"; output.result = Entities.Common.Result.Success; } } else if (getUserOut.result == Entities.Common.Result.Success) { output.message = "El valor a transferir supera el balance de la cuenta de origen"; output.result = Entities.Common.Result.Success; } } else if (validateAccesFunctionOut.result == Entities.Common.Result.Success) { output.message = "Esta funcionalidad no se encuentra disponible para no usuarios"; } return(output); }
public DeleteBalanceOut DeleteBalance(DeleteBalanceIn input) { var output = new DeleteBalanceOut() { result = Entities.Common.Result.Error }; var request = new Business.User.User(); var getUserInfoOut = request.GetUsers(new MethodParameters.User.GetUsersIn() { }).listUsers.FirstOrDefault(x => x.usrID == input.currentUser.usrID); var permissionRequest = new Business.Permission.Permission(); var validateAccesFunctionOut = permissionRequest.GetPermissionByRole(new MethodParameters.Permission.GetPermissionByRoleIn() { role = getUserInfoOut.usr_role }); if (validateAccesFunctionOut.result == Entities.Common.Result.Success && validateAccesFunctionOut.listPermissions.FirstOrDefault(x => x.pm_code == "04") != null) { var getUserOut = request.GetUser(new MethodParameters.User.GetUserIn() { usr_userName = input.usr_userNameDestiny }); if (getUserOut.result == Entities.Common.Result.Success && getUserOut.user.usr_balance >= input.valueTransfer) { var deleteBalanceOut = request.DeleteBalance(new MethodParameters.User.DeleteBalanceIn() { usr_userNameDestiny = input.usr_userNameDestiny, valueTransfer = input.valueTransfer }); if (deleteBalanceOut.result == Entities.Common.Result.Success) { output.result = deleteBalanceOut.result; output.result = Entities.Common.Result.Success; } } else if (getUserOut.result == Entities.Common.Result.Success) { output.message = "La operación que intenta realizar supera el balance actual"; } } else if (validateAccesFunctionOut.result == Entities.Common.Result.Success) { output.message = "Esta funcionalidad no se encuentra disponible para usuarios no Administrador"; } return(output); }
public CreateUserOut Create(CreateUserIn input) { var output = new CreateUserOut() { result = Entities.Common.Result.Error }; var request = new Business.User.User(); var getUserInfoOut = request.GetUsers(new MethodParameters.User.GetUsersIn() { }).listUsers.FirstOrDefault(x => x.usrID == input.currentUser.usrID); var permissionRequest = new Business.Permission.Permission(); var validateAccesFunctionOut = permissionRequest.GetPermissionByRole(new MethodParameters.Permission.GetPermissionByRoleIn() { role = getUserInfoOut.usr_role }); if (validateAccesFunctionOut.result == Entities.Common.Result.Success && validateAccesFunctionOut.listPermissions.FirstOrDefault(x => x.pm_code == "01") != null) { var password = Common.Security.Encryption.Encrypt(input.usr_password, input.usr_userName); var createUsertOut = request.CreateUser(new MethodParameters.User.CreateUserIn() { user = new Entities.Database.User() { usr_userName = input.usr_userName, usr_password = password, usr_fullName = input.usr_fullName, usr_documentType = input.usr_documentType, usr_numberDocument = input.usr_numberDocument, usr_email = input.usr_email, usr_role = input.usr_role } }); if (createUsertOut.result == Entities.Common.Result.Success) { output.result = Entities.Common.Result.Success; } } else if (validateAccesFunctionOut.result == Entities.Common.Result.Success) { output.message = "Esta funcionalidad no se encuentra disponible para usuarios no Administrador"; } return(output); }
public GetUserOut GetUser(GetUserIn input) { var output = new GetUserOut() { result = Entities.Common.Result.Error }; var request = new Business.User.User(); var getUserByFilterOut = request.GetUser(new MethodParameters.User.GetUserIn() { usr_userName = input.usr_userName }); if (getUserByFilterOut.user != null) { var user = new MethodParameters.Controllers.SystemManagementApi.User.GetUserOut.UserResult() { usrID = getUserByFilterOut.user.usrID, usr_code = getUserByFilterOut.user.usr_code, usr_userName = getUserByFilterOut.user.usr_userName, usr_password = getUserByFilterOut.user.usr_password, usr_fullName = getUserByFilterOut.user.usr_fullName, usr_documentType = getUserByFilterOut.user.usr_documentType, usr_numberDocument = getUserByFilterOut.user.usr_numberDocument, usr_email = getUserByFilterOut.user.usr_email, usr_balance = getUserByFilterOut.user.usr_balance, usr_role = getUserByFilterOut.user.usr_role, usr_creationUser = getUserByFilterOut.user.usr_creationUser, usr_creationDate = getUserByFilterOut.user.usr_creationDate, usr_modificationUser = getUserByFilterOut.user.usr_modificationUser, usr_modificationDate = getUserByFilterOut.user.usr_modificationDate, usr_status = getUserByFilterOut.user.usr_status }; output.resultGetUser = user; } if (getUserByFilterOut.result == Entities.Common.Result.Success) { output.result = Entities.Common.Result.Success; } return(output); }
public AddBalanceOut AddBalance(AddBalanceIn input) { var output = new AddBalanceOut() { result = Entities.Common.Result.Error }; var request = new Business.User.User(); var getUserOut = request.GetUsers(new MethodParameters.User.GetUsersIn() { }).listUsers.FirstOrDefault(x => x.usrID == input.currentUser.usrID); var permissionRequest = new Business.Permission.Permission(); var validateAccesFunctionOut = permissionRequest.GetPermissionByRole(new MethodParameters.Permission.GetPermissionByRoleIn() { role = getUserOut.usr_role }); if (validateAccesFunctionOut.result == Entities.Common.Result.Success && validateAccesFunctionOut.listPermissions.FirstOrDefault(x => x.pm_code == "03") != null) { var createUsertOut = request.AddBalance(new MethodParameters.User.AddBalanceIn() { usr_userNameDestiny = input.usr_userNameDestiny, valueTransfer = input.valueTransfer }); if (createUsertOut.result == Entities.Common.Result.Success) { output.usrID = createUsertOut.usrID; output.result = Entities.Common.Result.Success; } } else if (validateAccesFunctionOut.result == Entities.Common.Result.Success) { output.message = "Esta funcionalidad no se encuentra disponible para usuarios no Administrador"; } return(output); }
public LoginOut Login(LoginIn input) { var output = new LoginOut() { result = Entities.Common.Result.Error }; var request = new Business.User.User(); var getUserOut = request.GetUser(new MethodParameters.User.GetUserIn() { usr_userName = input.usr_userName }); if (getUserOut.result == Entities.Common.Result.Success) { if (getUserOut.user.usr_userName == input.usr_userName) { var passwordIn = Common.Security.Encryption.Encrypt(input.usr_password, getUserOut.user.usr_userName); var passwordBd = getUserOut.user.usr_password; if (passwordIn == passwordBd) { string sessionId = Guid.NewGuid().ToString(); var authentication = new SystemManagement.Business.Authentication.Authentication(); var createSessionOut = authentication.CreateSession(new MethodParameters.Authentication.CreateSessionIn() { sessionId = sessionId, userId = getUserOut.user.usrID }); if (createSessionOut.result == Entities.Common.Result.Success) { output.sessionId = sessionId; output.user = getUserOut.user;; var jwtManager = new SystemManagement.Business.Authentication.JwtManager(); var generateTokenOut = jwtManager.GenerateToken(new MethodParameters.Authentication.JwtManager.GenerateTokenIn() { sessionId = sessionId, usrID = getUserOut.user.usrID }); if (generateTokenOut.result == Entities.Common.Result.Success) { output.token = generateTokenOut.token; output.user = getUserOut.user; output.result = Entities.Common.Result.Success; } } } else { output.message = "Credenciales incorrectas, verifique e intente nuevamente"; } } else { output.message = "Credenciales incorrectas, verifique e intente nuevamente"; } } else { output.message = "Credenciales incorrectas, verifique e intente nuevamente"; } return(output); }
public void CreateUser(string data) { user = new Business.User.User(); user.CreateUser(data); }
public string HelloWorld(string data) { user = new Business.User.User(); return(user.HelloWorld(data)); }