public async Task <String> Login(LoginVMO userloginVMO) { LoginDTO userLogin = LoginMapper.MapToDTO(userloginVMO); String token = await this.request.GetToken(userLogin); return(token); }
internal static int insertUser(User user) { user.roleId = 1; int res = LoginMapper.insertUser(user); return(res); }
/// <summary> /// Controller para que el usuario inicie sesion /// </summary> /// <param name="loginDTO">Objeto login a ingresar a la aplicaicon</param> /// <returns>Objeto tipo Entity con los datos del usuario que se a logeado </returns> /// <exception cref="LoginUserNotFoundException">El objeto a retornar es nulo</exception> /// <exception cref="DatabaseException">Algun error con la base de datos</exception> //POST : /api/Login public ActionResult <LoginDTO> Login([FromBody] LoginDTO loginDTO) { try{ LoginMapper LoginMapper = MapperFactory.createLoginMapper(); Entity entity = LoginMapper.CreateEntity(loginDTO); GetUserCommand command = CommandFactory.loginGetUserCommand((Login)entity); command.Execute(); Login answer = command.GetResult(); if (answer == null) { throw new LoginUserNotFoundException("Correo o clave invalido"); } else { DTO lDTO = LoginMapper.CreateDTO(answer); return(Ok(lDTO)); } } catch (DatabaseException ex) { _logger?.LogError(ex, "Database exception cuando se intento iniciar sesion."); return(StatusCode(500, ex.Message)); } catch (LoginUserNotFoundException) { return(BadRequest(new { message = "Correo o clave invalida." })); } }
public ActionResult Registration(RegisterModel model) { if (ModelState.IsValid) { try { login.Create(LoginMapper.GetBLLEntity(model)); if (Request.IsAjaxRequest()) { return(Json(new { Result = "You have registered!" })); } return(RedirectToRoute("Home")); } catch (Exception e) { ModelState.AddModelError(e.Message, e.Message); } } string errorMessage = GetModelStateErrors(ModelState); if (Request.IsAjaxRequest()) { return(Json(new { Result = errorMessage })); } return(View()); }
public UsuarioAppService(IUnitOfWork unitOfWork, IUsuarioService usuarioService, LoginMapper loginMapper, ErroMapper erroMapper) { _usuarioService = usuarioService; _unitOfWork = unitOfWork; _loginMapper = loginMapper; _erroMapper = erroMapper; }
public void SetUp() { _loginMapper = MapperFactory.createLoginMapper(); //DTO _loginDto = new LoginDTO(); _loginDto.email = "*****@*****.**"; _loginDto.password = "******"; _loginDto.id = 1; var rolesdto = new List <RoleDTO>(); rolesdto.Add(new RoleDTO(1, "Cliente")); _loginDto.roles = rolesdto; _loginDtoList = new List <LoginDTO>(); _loginDtoList.Add(_loginDto); //Entity _loginEntity = new Login(); _loginEntity.email = "*****@*****.**"; _loginEntity.password = "******"; _loginEntity.Id = 1; var roles = new List <Role>(); roles.Add(new Role(1, "Cliente")); _loginEntity.roles = roles; _loginEntityList = new List <Login>(); _loginEntityList.Add(_loginEntity); }
public IActionResult Login(LoginVm login) { using (SHA256 sha256Hash = SHA256.Create()) { if (ModelState.IsValid) { UserVm user = _userService.GetByEmail(login.Email); if (user != null) { var hashPassord = _userService.GetHash(sha256Hash, login.Password); if (user.Password == hashPassord) { //user.Password = login.Password; var token = _userService.Authenticate(user.Email); LoginVm loginVm = LoginMapper.Map(user, token); return(Ok(ResponseManager.GenerateResponse(null, (int)MessageType.Ok, loginVm))); } } } //return BadRequest(new { message = "Email lub hasło są niepoprawne" }); return(Ok(ResponseManager.GenerateResponse("Błąd: Email lub hasło są niepoprawne", (int)MessageType.Error, null))); } }
public void TearDown() { _loginDto = null; _loginMapper = null; _loginEntity = null; _loginEntityList = null; _loginDtoList = null; }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var identity = new ClaimsIdentity(context.Options.AuthenticationType); //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); LoginViewModel user = new LoginViewModel(); user.Email = context.UserName; user.Password = context.Password; var userDTO = LoginMapper.VMtoDTOLogin(user); var currentUser = service.Login(userDTO); if (currentUser != null) { identity.AddClaim(new Claim("Role", currentUser.Role == Role.Volunteer ? "0" : "1")); identity.AddClaim(new Claim("ApprovalStatus", currentUser.ApprovalStatus == ApprovalStatus.Pending ? "0" : currentUser.ApprovalStatus == ApprovalStatus.Approved ? "1" : "2")); identity.AddClaim(new Claim("UserID", Convert.ToString(currentUser.UserID))); identity.AddClaim(new Claim("Email", Convert.ToString(currentUser.Email))); identity.AddClaim(new Claim("FirstName", Convert.ToString(currentUser.FirstName))); identity.AddClaim(new Claim("LastName", Convert.ToString(currentUser.LastName))); var props = new AuthenticationProperties(new Dictionary <string, string> { { "Email", context.UserName }, { "Role", currentUser.Role == Role.Volunteer?"0":"1" }, { "ApprovalStatus", currentUser.ApprovalStatus == ApprovalStatus.Pending?"0": currentUser.ApprovalStatus == ApprovalStatus.Approved ? "1":"2" }, { "FirstName", currentUser.FirstName }, { "LastName", currentUser.LastName }, { "Image", currentUser.Image }, { "UserID", Convert.ToString(currentUser.UserID) } }); var ticket = new AuthenticationTicket(identity, props); context.Validated(ticket); //else //{ // //context.SetError("invalid_grant", "Provided username and password is not matching, Please retry!"); // //context.Rejected(); //} } else { context.SetError("invalid_grant", "Provided username and password is not matching, Please retry!"); //context.Rejected(); } return; }
private void buttonLogin_Click(object sender, EventArgs e) { LoginMapper lm = new LoginMapper(); string username = usernameBox.Text.Trim().ToString(); string password = passwordBox.Text.Trim().ToString(); /*Console.WriteLine(username + " " + password);*/ User u = lm.checkExist(username, password); if (u != null) { LoginPanel.Controls.Clear(); countGabim = 0; if (u.Statusi == 2 || u.Statusi == 3) { ProfPanel f2 = new ProfPanel(u); f2.TopLevel = false; LoginPanel.Controls.Add(f2); f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f2.Dock = DockStyle.Fill; f2.Show(); } else if (u.Statusi == 4) { RektorPanel f2 = new RektorPanel(u); f2.TopLevel = false; LoginPanel.Controls.Add(f2); f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f2.Dock = DockStyle.Fill; f2.Show(); } else { StudentPanel f2 = new StudentPanel(u); f2.TopLevel = false; LoginPanel.Controls.Add(f2); f2.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; f2.Dock = DockStyle.Fill; f2.Show(); } } else { label3.ForeColor = System.Drawing.Color.Red; label3.Text = "Keni shenuar te dhenat gabim"; passwordBox.Clear(); countGabim++; } if (countGabim == 3) { MessageBox.Show("Keni shenuar 3-here te dhenat gabim"); Application.Exit(); } }
public static Boolean checkUserNameUnique(String usernName) { if (LoginMapper.checkUserNameUnique(usernName) == 0) { return(true); } return(false); }
/// <summary> /// Controller para cambiar la clave del usuario /// </summary> /// <param name="loginDTO">Objeto login a cambiar su clave</param> /// <returns>Objeto tipo Entity con los datos del usuario luego de cambiar su clave</returns> /// <exception cref="PasswordRecoveryException">El objeto a retornar es nulo</exception> /// <exception cref="DatabaseException">Algun error con la base de datos</exception> //POST : /api/Email public ActionResult <LoginDTO> Recovery([FromBody] LoginDTO loginDTO) { try{ LoginMapper LoginMapper = MapperFactory.createLoginMapper(); Entity entity = LoginMapper.CreateEntity(loginDTO); RecoveryPasswordCommand command = CommandFactory.RecoveryPasswordCommand((Login)entity); command.Execute(); Login objUser = command.GetResult(); if (objUser != null) { Console.WriteLine("Correo del usuario que modifico: "); Console.WriteLine(objUser.email); Console.WriteLine("Clave del usuario modificada: "); Console.WriteLine(objUser.password); //logica correo var message = new MimeMessage(); //From Address message.From.Add(new MailboxAddress("Vacanze Administracion", "*****@*****.**")); //To Address message.To.Add(new MailboxAddress("Usuario", address: objUser.email)); //Subject message.Subject = "Recuperacion De Contraseña : "; message.Body = new TextPart("plain") { Text = "Su contraseña nueva: " + objUser.password }; using (var client = new MailKit.Net.Smtp.SmtpClient()){ client.CheckCertificateRevocation = false; client.Connect("smtp.gmail.com", 587); client.Authenticate("*****@*****.**", "_Gx123456"); client.Send(message); client.Disconnect(true); client.Dispose(); } LoginDTO ldto = LoginMapper.CreateDTO(objUser); return(Ok(ldto)); } else { return(BadRequest(new { message = "Correo invalido." })); } } catch (DatabaseException ex) { _logger?.LogError(ex, "Database exception cuando se intenta mandar el correo con la nueva clave al cliente"); return(StatusCode(500, ex.Message)); } catch (PasswordRecoveryException) { return(BadRequest(new { message = "Correo invalido." })); } }
public ActionResult Users(List <MvcLogin> Entities) { if (ModelState.IsValid) { foreach (var item in Entities) { logins.UpDate(LoginMapper.GetBLLEntity(item)); } } return(Redirect("Users")); }
public ResponseBaseDto <OutsourcerLoginResponseDto> LoginOutsourcer(OutsourcerLoginRequestDto dto) { var requestDomain = LoginMapper.Map(dto); var responseDomain = LoginService.LoginOutsourcer(requestDomain); var responseDto = LoginMapper.Map(responseDomain); return(string.IsNullOrEmpty(responseDto.Token) ? new ResponseBaseDto <OutsourcerLoginResponseDto> { Error = responseDomain.Message } : new ResponseBaseDto <OutsourcerLoginResponseDto> { Data = responseDto, IsSuccess = true }); }
private async Task <bool> IsValidUser(Login login) { var tokenDto = await loginService.ValidUser(LoginMapper.ToDto(login)); if (tokenDto == null) { HttpContext.Session.SetString("IsUserLogged", "false"); return(false); } HttpContext.Session.SetString("IsUserLogged", "true"); HttpContext.Session.SetString("User", tokenDto.Name); HttpContext.Session.SetString("TokenData", JsonConvert.SerializeObject(TokenMapper.ToEntity(tokenDto))); return(true); }
private void skinLabel3_Click(object sender, EventArgs e) { LoginState loginState = LoginMapper.Exist(Phone.Text.Trim(), Pwd.Text.Trim()); if (loginState == LoginState.sucess) { xilixili xilixili = new xilixili(); this.Visible = false; xilixili.ShowDialog(); this.Dispose(); this.Close(); } else { MessageBox.Show(StateString.GetLoginStateString(loginState)); } }
public void Create(BLLLogin prog) { DALLogin dallog = LoginMapper.GetDALEntity(prog); if (!IsEmailEnabled(dallog.Mail)) { throw new Exception("User with such email is exists!"); } if (!IsLoginEnabled(dallog.Login)) { throw new Exception("User with such login is exists!"); } uow.Logins.Create(dallog); uow.Programmers.Create(new DALProgrammer() { Id = dallog.Id }); uow.Commit(); }
public BLLLogin Login(string mailOrLogin, string password) { DALLogin dalprog; if (IsEnabled(mailOrLogin, out dalprog)) { if (IsPasswordEnabled(password)) { Expression <Func <DALLogin, bool> > expLogin = u => u.Login == mailOrLogin; Expression <Func <DALLogin, bool> > expmail = u => u.Mail == mailOrLogin; if (uow.Logins.GetByPredicate(expLogin) == null) { return(LoginMapper.GetBLLEntity(uow.Logins.GetByPredicate(expmail))); } return(LoginMapper.GetBLLEntity(uow.Logins.GetByPredicate(expLogin))); } } throw new Exception("check your data!"); }
internal static Boolean validation(string userName, string password) { User user = LoginMapper.selectUserByUserName(userName); if (user == null) { return(false); } String token = genPassword(userName, password, user.salt); if (token == user.password) { return(true); } else { return(false); } }
public ActionResult Login(LoginPO form) { ActionResult response = null; LoginPO login = new LoginPO(); try { //Checks ModelState to be sure info inputted matches the current model if (ModelState.IsValid) { LoginDO dataObject = LoginMapper.LoginPOToDO(form); LoginDO databaseLogin = _dataAccess.ViewUserByUsername(dataObject); //Checks whether the inputted password and username are correct, and handles that properly if (databaseLogin == null || form.Password != databaseLogin.Password) { ModelState.AddModelError("Password", "Username or password incorrect, please try again."); response = View(); } else if (form.Password == databaseLogin.Password && form.Username == databaseLogin.Username) { Session["Username"] = databaseLogin.Username; Session["UserID"] = databaseLogin.UserId; Session["RoleID"] = databaseLogin.RoleId; //keeps user logged in for 5 minutes, after they log in they get sent to home page Session.Timeout = 5; response = RedirectToAction("Index", "Home"); } } else { response = View(); } } catch (Exception ex) { Logger.Log("Fatal", ex.TargetSite.ToString(), ex.Message, ex.StackTrace); } return(response); }
public async Task <RespuestaDto <Login> > CreateLogin(Login login) { var loginResult = new Login(); try { await Task.Delay(10); var resultado = _loginRepository.CreateLogin(LoginMapper.LoginToEntity(login), conStr); if (resultado.Result != null) { loginResult = LoginMapper.EntityToLogin(resultado.Result); } } catch (Exception ex) { throw new Exception($"{ex.Message}"); } return(MensajeRespuesta.CrearMensajeRespuesta(loginResult, string.Empty, true)); }
public async Task <RespuestaDto <Login> > GetLogin(string user, string pass) { var login = new Login(); try { await Task.Delay(10); var datos = _loginRepository.GetLogin(user, pass, conStr); if (datos.Result != null) { login = LoginMapper.EntityToLogin(datos.Result); } } catch (Exception ex) { throw new Exception($"{ex.Message}"); } return(MensajeRespuesta.CrearMensajeRespuesta(login, string.Empty, true)); }
/// <summary> /// 后台登陆判断超级管理员。普通管理员 /// </summary> /// <param name="userPhone">账号</param> /// <param name="userPwd">密码</param> /// <returns></returns> internal static object Decryption(string userPhone, string userPwd) { var user = LoginMapper.GetLogin(userPhone); string UserPwd = TrickLock.WeiYiJieMiGuid(user.UserPwd); var Rples = LoginMapper.Rples(userPhone); if (Rples == null) { return(3); } else if (Rples.user_roles1 == "超级管理员") //超级管理员 { if (UserPwd == userPwd) { return(1); } else { return(0); } } else if (Rples.user_roles1 == "管理员")//普通管理员 { if (UserPwd == userPwd) { return(-1); } else { return(0); } } else //用户 { return(3); } }
private void btn_aceptar_Click(object sender, EventArgs e) { if (!validacionesForm()) { return; } lblactivacion.Visible = true; lblactivacion.Text = "Verificando usuario"; String usuario = txtusuario.Text.ToString(); String clave = txtpass.Text.ToString(); Entidades.Login login = LoginMapper.validar(usuario, clave); if (login != null) { this.Valido = true; Close(); } else { mensajeDeError(); } }
public ActionResult Login(LoginModel loginModel) { if (ModelState.IsValid) { try { var user = LoginMapper.GetMVCEntity(login.Login(loginModel.MailOrLogin, loginModel.Password)); FormsAuthentication.SetAuthCookie(user.Login, true); return(RedirectToRoute("Home")); } catch (Exception e) { ModelState.AddModelError(e.Message, e.Message); } } string errorMessage = GetModelStateErrors(ModelState); if (Request.IsAjaxRequest()) { return(Json(new { Result = errorMessage })); } return(View()); }
public void UpDate(BLLLogin prog) { uow.Logins.UpDate(LoginMapper.GetDALEntity(prog)); uow.Commit(); }
public LoginAppService(ILoginService loginService, LoginMapper loginMapper) { _loginService = loginService; _loginMapper = loginMapper; }
public IEnumerable <BLLLogin> GetAll() { return(LoginMapper.Map(uow.Logins.GetAll())); }
public BLLLogin Get(int id) { return(LoginMapper.GetBLLEntity(uow.Logins.GetById(id))); }
internal static object DecryptionHotelID(string userPhone) { var user = LoginMapper.GetLogin(userPhone); return(user.HotelID); }