예제 #1
0
        public static CustomApplicationUser fromUtilisateurContract(UtilisateurContract userC)
        {
            if (userC == null)
                return null;

            CustomApplicationUser u = new CustomApplicationUser();
            u.UserName = userC.Login;
            u.Id = userC.Login;
            u.Points = userC.Points;

            return u;
        }
예제 #2
0
        public static UtilisateurContract fromCustomApplicationUser(CustomApplicationUser customUser)
        {
            if (customUser == null)
                return null;

            UtilisateurContract u = new UtilisateurContract();
            u.Login = customUser.UserName;
            u.Password = customUser.PasswordHash;
            u.Prenom = customUser.UserName;
            u.Nom = customUser.UserName;
            u.Points = customUser.Points;

            return u;
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new CustomApplicationUser() { UserName = model.UserName };
                var result = UserManager.Create(user, model.Password);
                if (result)
                {
                    await SignInAsync(user, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    //AddErrors(result);
                }
            }

            // Si nous sommes arrivés là, un échec s’est produit. Réafficher le formulaire
            return View(model);
        }
        private async Task SignInAsync(CustomApplicationUser user, bool isPersistent)
        {
            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
            CustomIdentity identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

            AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
        }