Ejemplo n.º 1
0
 public static DTO.LoginDTO GetLoginFromRow(DAL.LoginDAL.LOGIN_GETALLRow row)
 {
     DTO.LoginDTO obj = new DTO.LoginDTO();
     obj.UserName = row.userName;
     obj.Password = row.password;
     obj.Permiso  = row.nombrePermiso;
     return(obj);
 }
Ejemplo n.º 2
0
        public static List <DTO.LoginDTO> GetLogin(string userName, string password)
        {
            ProyectoClinica.App_Code.DAL.LoginDALTableAdapters.LOGIN_GETALLTableAdapter adapter = new ProyectoClinica.App_Code.DAL.LoginDALTableAdapters.LOGIN_GETALLTableAdapter();
            DAL.LoginDAL.LOGIN_GETALLDataTable table = adapter.GetAllLogin(userName, password);
            List <DTO.LoginDTO> list = new List <DTO.LoginDTO>();

            foreach (var row in table)
            {
                DTO.LoginDTO obj = GetLoginFromRow(row);
                list.Add(obj);
            }
            return(list);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> LoginParticulier([FromBody] DTO.LoginDTO loginDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var           authParticuliers = _context.Particuliers;
            ScryptEncoder encoder          = new ScryptEncoder();
            Particulier   particulierFound = authParticuliers.FirstOrDefault(par => par.Mail == loginDTO.Mail);

            if (particulierFound == null)
            {
                return(NotFound());
            }

            if (!encoder.Compare(loginDTO.MotDePasse, particulierFound.MotDePasse))
            {
                return(Unauthorized());
            }

            var claims = new[]
            {
                new Claim(JwtRegisteredClaimNames.Sub, particulierFound.Mail),
                new Claim(JwtRegisteredClaimNames.Jti, await _jwtOptions.JtiGenerator()),
                new Claim(JwtRegisteredClaimNames.Iat,
                          ToUnixEpochDate(_jwtOptions.IssuedAt).ToString(),
                          ClaimValueTypes.Integer64),
            };

            // Create the JWT security token and encode it.
            JwtSecurityToken jwt = new JwtSecurityToken(
                issuer: _jwtOptions.Issuer,
                audience: _jwtOptions.Audience,
                claims: claims,
                notBefore: _jwtOptions.NotBefore,
                expires: _jwtOptions.Expiration,
                signingCredentials: _jwtOptions.SigningCredentials
                );
            var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt);


            // Serialize and return the response
            var response = new
            {
                access_token = encodedJwt,
                expires_in   = (int)_jwtOptions.ValidFor.TotalSeconds
            };

            return(Ok(response));
        }
        // GET: Users/login
        public async Task <IActionResult> Login([Bind("email,password")] DTO.LoginDTO dto)
        {
            //hashing password
            byte [] passwordBytes = Encoding.ASCII.GetBytes(dto.password);
            var     md5           = new MD5CryptoServiceProvider();

            byte [] md5data      = md5.ComputeHash(passwordBytes);
            string  passwordHash = Encoding.ASCII.GetString(md5data);


            var users = await _context.Users
                        .SingleOrDefaultAsync(m => m.email == dto.email && m.passwordHash == passwordHash);

            if (users == null)
            {
                ModelState.AddModelError("", "Wrong password or email.");
                return(View());
            }

            //updating flags in session
            HttpContext.Session.SetInt32("isSignedIn", 1);

            if (users.admin == true)
            {
                HttpContext.Session.SetInt32("Role", 2);
            }
            else
            {
                HttpContext.Session.SetInt32("Role", 1);
            }

            HttpContext.Session.SetInt32("CurrentUserId", users.Id);
            HttpContext.Session.SetString("CurrentUsername", users.firstName + " " + users.lastName);

            users.lastSeen = DateTime.Now;
            _context.Users.Update(users);

            return(View("Profile", users));
        }