Ejemplo n.º 1
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();


            ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                OAuthDefaults.AuthenticationType);

            ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                  CookieAuthenticationDefaults.AuthenticationType);

            AuthenticationProperties properties = CreateProperties(user.UserName);

            var AllUser   = interfaceObj.GetModel();
            var regUserId = AllUser.Where(x => x.UserId == user.Id).Select(x => x.Id).FirstOrDefault();


            RegisterUser RUserData = new RegisterUser();

            var Udata = interfaceObj.GetModelById(Convert.ToInt32(regUserId));

            properties.Dictionary.Add("Id", Udata.Id.ToString());
            properties.Dictionary.Add("FirstName", Udata.FirstName);
            properties.Dictionary.Add("MiddelName", Udata.MiddelName);
            properties.Dictionary.Add("LastName", Udata.LastName);
            properties.Dictionary.Add("Email", Udata.Email);
            properties.Dictionary.Add("Phone", Udata.Phone);
            properties.Dictionary.Add("Role", Udata.Role);

            string base64String = null;
            string path         = System.Web.HttpContext.Current.Server.MapPath(Udata.Image);

            using (System.Drawing.Image image = System.Drawing.Image.FromFile(path))
            {
                using (MemoryStream m = new MemoryStream())
                {
                    image.Save(m, image.RawFormat);
                    byte[] imageBytes = m.ToArray();
                    base64String = Convert.ToBase64String(imageBytes);
                }
            }
            properties.Dictionary.Add("Image", base64String);


            AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(cookiesIdentity);
        }
Ejemplo n.º 2
0
        public string GetStateName(int?id)
        {
            var State = stateObj.GetModelById(id);

            return(State.StateName.ToString());
        }
Ejemplo n.º 3
0
        public string GetCountryName(int?id)
        {
            var Country = countryObj.GetModelById(id);

            return(Country.CountryName.ToString());
        }
Ejemplo n.º 4
0
        public string GetCityName(int?id)
        {
            var City = cityObj.GetModelById(id);

            return(City.CityName.ToString());
        }