Exemple #1
0
        // GET: Trainee/Create
        public ActionResult Create(string returnurl = "")
        {
            string username = User.Identity.Name;
            var    user     = (from us in authDb.Users
                               where string.Compare(us.Username, username, StringComparison.OrdinalIgnoreCase) == 0
                               select us).FirstOrDefault();

            if (user == null)
            {
                return(null);
            }
            var selectedUser = new CustomMembershipUser(user);

            if (selectedUser == null)
            {
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                TraineeViewModel trainee = new TraineeViewModel
                {
                    Name     = selectedUser.FirstName + " " + selectedUser.LastName,
                    Email    = selectedUser.Email,
                    UserName = selectedUser.UserName
                };
                ViewBag.ReturnUrl = returnurl;
                return(View(trainee));
            }
        }
 public ActionResult RegisterNewUser(User usuario)
 {
     if (ModelState.IsValid)
     {
         // Attempt to register the user
         var user = new CustomMembershipUser("CustomMembershipProvider",
                                             usuario.UserName,
                                             usuario.Id,
                                             usuario.Email,
                                             "",
                                             "",
                                             true,
                                             false,
                                             usuario.CreateDate,
                                             DateTime.Now,
                                             DateTime.Now,
                                             DateTime.Now,
                                             DateTime.Now)
         {
             User = usuario
         };
         var createStatus = MembershipService.CreateUser(user);
         if (createStatus == MembershipCreateStatus.Success)
         {
             FormsService.SignIn(user.UserName, false /* createPersistentCookie */);
             return(RedirectToAction("Index", "UserManagement"));
         }
         ModelState.AddModelError("", ErrorCodes.ErrorCodeToString(createStatus));
     }
     // If we got this far, something failed, redisplay form
     return(View(usuario));
 }
Exemple #3
0
        public void CreateCookie(CustomMembershipUser user, bool remebmerMe)
        {
            CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();

            serializeModel.UserId    = user.UserId;
            serializeModel.UserName  = user.UserName;
            serializeModel.FirstName = user.FirstName;
            serializeModel.LastName  = user.LastName;

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            string userData = serializer.Serialize(serializeModel);

            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
                0,
                user.UserName,
                DateTime.Now,
                DateTime.Now.AddMinutes(3000),
                remebmerMe,
                userData,
                FormsAuthentication.FormsCookiePath);

            string     encTicket = FormsAuthentication.Encrypt(authTicket);
            HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);

            Response.Cookies.Add(faCookie);
        }
Exemple #4
0
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var user = new CustomMembershipUser();


            status = MembershipCreateStatus.Success;
            return(user);
        }
Exemple #5
0
        private void ActualizarRol(CustomMembershipUser usuario)
        {
            var username = usuario.UserName;
            var idrol    = usuario.UserRoleId;

            var update = new UpdatePerfilService();

            update.Update(username, idrol);
        }
Exemple #6
0
        protected void Application_PostAuthenticateRequest(object sender, EventArgs e)
        {
            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value);
                var                  userdata    = UserDataModel.CreateUserData(ticket.UserData);
                FormsIdentity        identity    = (FormsIdentity)HttpContext.Current.User.Identity;
                CustomMembershipUser user        = (CustomMembershipUser)Membership.GetUser(identity.Name);
                var                  principal   = new CustomPrincipal(identity, user, userdata.YearStart, userdata.YearEnd);
                HttpContext.Current.User = principal;
            }
        }
Exemple #7
0
        public ActionResult ChangePassword()
        {
            if (ac.GetUser("administrator") == null)
            {
                return(RedirectToAction("Index", "Login"));
            }

            MembershipUser       user       = ac.GetUser();
            CustomMembershipUser customUser = (CustomMembershipUser)user;

            LoginChangePassword vm = new LoginChangePassword();

            vm.UserId = customUser != null ? customUser.Id : 0;
            vm.CPF    = customUser != null ? customUser.CPF : "";
            return(View(vm));
        }
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            var cacheKey = string.Format("UserData_{0}", username);
            //if (HttpRuntime.Cache[cacheKey] != null)
            //   return (CustomMembershipUser)HttpRuntime.Cache[cacheKey];

            var res = string.Empty;



            ProxyApiUsuario objUsuario = new ProxyApiUsuario();

            ObtenerUsuarioResponse resultado = (ObtenerUsuarioResponse)objUsuario.ObtenerUsuarioPorCorreo(username);

            HttpContext.Current.Session["mensaje_validateuser"] = resultado.status.mensaje;

            if (resultado == null)
            {
                return(null);
            }
            // if (resultado.ListaRoles.Any() == false) return null;

            //elinando mensaje de errores
            HttpContext.Current.Session["mensaje_validateuser"] = null;

            var usuario =
                new Usuario(
                    resultado.Usuario.usua_id,
                    resultado.Usuario.usua_nomb,
                    resultado.Usuario.usua_email
                    );



            SessionWrapper user = new SessionWrapper();

            user.Usuario = usuario;


            var membershipUser = new CustomMembershipUser(usuario);



            //  HttpRuntime.Cache.Insert(cacheKey, membershipUser, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);

            return(membershipUser);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            using (AuthenticationDB dbContext = new AuthenticationDB())
            {
                var user = (from us in dbContext.Users
                            where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0
                            select us).FirstOrDefault();

                if (user == null)
                {
                    return(null);
                }
                var selectedUser = new CustomMembershipUser(user);

                return(selectedUser);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            using (MixupActivity.Context.AppContext dbContext = new MixupActivity.Context.AppContext())
            {
                var user = (from us in dbContext.Persons
                            where string.Compare(username, us.LoginId, StringComparison.OrdinalIgnoreCase) == 0
                            select us).FirstOrDefault();

                if (user == null)
                {
                    return(null);
                }
                var selectedUser = new CustomMembershipUser(user);

                return(selectedUser);
            }
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            using (EventRegistrationEntities dbContext = new EventRegistrationEntities())
            {
                var customer = (from us in dbContext.Customers.Include("CustomerRoles")
                                where string.Compare(username, us.Email, StringComparison.OrdinalIgnoreCase) == 0
                                select us).FirstOrDefault();

                if (customer == null)
                {
                    return(null);
                }
                var selectedUser = new CustomMembershipUser(customer);

                return(selectedUser);
            }
        }
Exemple #12
0
        // GET: User By ID
        public ActionResult GetUserById(int?id)
        {
            var resultUser = new UserViewModel();

            if (id > 0)
            {
                CustomMembershipUser user = (CustomMembershipUser)Membership.GetUser(id, true);
                resultUser.Username = user.Data.Username;
            }

            if (resultUser != null)
            {
                return(View(resultUser));
            }

            return(View("~/Views/Home/Index.cshtml"));
        }
 public ActionResult RegisterNewAdvertiser(AdvertiserVM model)
 {
     if (model.Advertiser != null && model.Latitude != null && model.Longitude != null)
     {
         model.Advertiser.Latitude  = double.Parse(model.Latitude, CultureInfo.InvariantCulture);
         model.Advertiser.Longitude = double.Parse(model.Longitude, CultureInfo.InvariantCulture);
     }
     if (model.IsValid)
     {
         // Attempt to register the user
         var city    = uow.Cities.Lista().SingleOrDefault(c => c.Name == model.City);
         var address = uow.Adresses.Crear();
         address.PostalCode       = model.PostalCode;
         address.Street           = model.Street;
         address.City             = city;
         model.Advertiser.Address = address;
         var user = new CustomMembershipUser("CustomMembershipProvider",
                                             model.Advertiser.UserName,
                                             model.Advertiser.Id,
                                             model.Advertiser.Email,
                                             "",
                                             "",
                                             true,
                                             false,
                                             model.Advertiser.CreateDate,
                                             DateTime.Now,
                                             DateTime.Now,
                                             DateTime.Now,
                                             DateTime.Now)
         {
             Advertiser = model.Advertiser
         };
         var createStatus = MembershipService.CreateUser(user);
         if (createStatus == MembershipCreateStatus.Success)
         {
             FormsService.SignIn(user.UserName, false /* createPersistentCookie */);
             return(RedirectToAction("Index", "AdvertisersManagement"));
         }
         ModelState.AddModelError("", ErrorCodes.ErrorCodeToString(createStatus));
     }
     // If we got this far, something failed, redisplay form
     ModelState.AddModelError("City", "Introduzca su posición en el mapa");
     return(View(model));
 }