Exemplo n.º 1
0
        public async Task <ActionResult <string> > Post(TestUserParameters model)
        {
            var user = await _signInManager.UserManager.FindByEmailAsync(model.UserName);

            var result = await _signInManager.CheckPasswordSignInAsync(user, model.Password, false);

            // var userPrincipal = await _signInManager.CreateUserPrincipalAsync(user);
            //  var identity = userPrincipal.Identity;
            if (result.Succeeded)
            {
                var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
                var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);

                var token = new JwtSecurityToken(_config["Jwt:Issuer"],
                                                 _config["Jwt:Issuer"],
                                                 null,
                                                 expires: DateTime.Now.AddMinutes(5),
                                                 signingCredentials: credentials);

                return(new JwtSecurityTokenHandler().WriteToken(token));
            }
            return(JsonConvert.SerializeObject("Invalid"));

            /*           var mi="d";
             *    if (!_signInManager.IsSignedIn(User))
             *    {
             *          var result = _signInManager.PasswordSignInAsync("*****@*****.**", "Lastdon1!", true, lockoutOnFailure: true);
             *          var user = await _signInManager.UserManager.FindByEmailAsync("*****@*****.**");
             *        var userPrincipal = await _signInManager.CreateUserPrincipalAsync(user);
             *        var identity = userPrincipal.Identity;
             *          if (_signInManager.IsSignedIn(userPrincipal))
             *             {
             *         var pi =  _dataservice.GetSkills();
             *         return JsonConvert.SerializeObject(pi);
             *             }
             *    }
             *
             *         //var profile =  _dataservice.GetProfile(_userManager.GetUserId(User));
             *       //return new string[] { pi[0].Value, pi[0].Text };
             *        //return new string[] {" pi.Designation", "pi.About" };
             *          return JsonConvert.SerializeObject(_signInManager.IsSignedIn(User));
             *    }*/
        }
Exemplo n.º 2
0
        public async Task<ActionResult<string>> Post(TestUserParameters model)
        {    
     
          //    var result = _signInManager.PasswordSignInAsync(model.UserName, model.Password, true, lockoutOnFailure: true);
          //  var fg=  _signInManager.SignOutAsync();
              var user = await _signInManager.UserManager.FindByEmailAsync(model.UserName);

           var userPrincipal = await _signInManager.CreateUserPrincipalAsync(user);
           var identity = userPrincipal.Identity;
            
            //var pi =  _dataservice.GetSkills();
            var videos =  _dataservice.GetVideos("626f8045-c466-4036-876d-99d8ebbbf51a");
             return JsonConvert.SerializeObject(videos);
               //  }  
        
        
             //var profile =  _dataservice.GetProfile(_userManager.GetUserId(User));
           //return new string[] { pi[0].Value, pi[0].Text };
            //return new string[] {" pi.Designation", "pi.About" };
            //  return JsonConvert.SerializeObject("h");
        }