Пример #1
0
 public IActionResult ValidateUser([FromBody] LoginDto login)
 {
     if (login == null)
     {
         output.status      = "Failure";
         output.description = "Send a json file";
     }
     else
     {
         try
         {
             //compares the email id sent by the currnet user and the email id stored in the database
             var user = context.users.Where(e => e.Email.Equals(login.email.Trim())).FirstOrDefault();
             if (user == null)
             {
                 output.status      = "Error";
                 output.description = "user is not registered";
             }
             //encrypts the password sent by the current user for validation
             Encrypt encrypt       = new Encrypt();
             var     passwordCheck = encrypt.Encryption(login.password, user.Key, user.IV);
             var     id            = from e in context.users
                                     where e.Email.Equals(login.email.Trim()) && e.Password.Equals(passwordCheck)
                                     select e.UserId;
             if (id == null || id.Count() == 0)
             {
                 output.status      = "error";
                 output.description = "invalid password";
             }
             else
             {
                 var token = TokenController.GenerateToken(login.email);
                 return(new JsonResult(new { AccessToken = token, UserId = user.GuserId }));
             }
         }
         catch (Exception e)
         {
             output.status      = "error";
             output.description = e.Message;
         }
     }
     return(new JsonResult(output));
 }
Пример #2
0
        public IActionResult ValidateUser([FromBody] LoginDto login)
        {
            if (login == null)
            {
                return(new JsonResult(new List <object>()
                {
                    new { Error = "no json file", Description = "send a json " }
                }));
            }
            User user = (from e in Context.Users
                         where e.Email.Equals(login.email.Trim())
                         select e).FirstOrDefault();

            if (user == null)
            {
                return(new JsonResult(new { Error = "invalid user", Description = "try to register this " }));
            }
            Encrypt encrypt = new Encrypt();


            var PasswordCheck = encrypt.Encryption(login.password, user.key, user.iv);

            var id = from e in Context.Users
                     where e.Email.Equals(login.email.Trim()) && e.Password.Equals(PasswordCheck)
                     select e.UserId;

            if (id == null || id.Count() == 0)
            {
                return(new JsonResult(new List <object>()
                {
                    new { Error = "invalid password", Description = "" }
                }));
            }
            else
            {
                var Token = TokenController.GenerateToken(login.email);
                return(Ok(new JsonResult(new  { AccessToken = Token, UserId = user.GuserId })));
            }
        }