コード例 #1
0
        public IDandToken Registration(AdminDto userdto)
        {
            if (ModelState.IsValid == false)
            {
                return(new IDandToken());
            }


            IdentityResult result = repos.CreateAdmin(userdto);

            if (result.Succeeded)
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    Dictionary <string, string> tokenDetails = null;

                    HttpClient client = new HttpClient();
                    client.BaseAddress = new Uri("http://localhost:4700/");
                    var login = new Dictionary <string, string>
                    {
                        { "grant_type", "password" },
                        { "username", userdto.Email },
                        { "password", userdto.Password },
                    };
                    var response = client.PostAsync("Token", new FormUrlEncodedContent(login)).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        tokenDetails = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content.ReadAsStringAsync().Result);
                        if (tokenDetails != null && tokenDetails.Any())
                        {
                            var          tokenNo = tokenDetails.FirstOrDefault().Value;
                            IdentityUser user    = repos.Find(userdto.Email, userdto.Password);
                            return(new IDandToken
                            {
                                ID = user.Id,
                                Token = tokenDetails.FirstOrDefault().Value
                            });
                        }
                    }
                }
            }

            return(new IDandToken());
        }