Пример #1
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginID, out provider, out providerUserId))
            {
                return(RedirectToAction("index", "mesannonces"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                // Insert a new user into the database
                using (toutokaz_dbEntities db = new toutokaz_dbEntities())
                {
                    tb_user_profile user = db.tb_user_profile.FirstOrDefault(u => u.username.ToLower() == model.Email.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.tb_user_profile.Add(new tb_user_profile {
                            username = model.Email
                        });
                        db.SaveChanges();

                        // Insert name into account table
                        int Id = WebSecurity.GetUserId(model.Email);
                        db.tb_account.Add(new tb_account
                        {
                            UserId          = Id,
                            firstname       = model.Prenom,
                            lastname        = model.Nom,
                            email           = model.Email,
                            username        = model.Email,
                            id_account_type = 1,
                            role            = "annonceur",
                            status          = "active",
                        });
                        db.SaveChanges();
                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.Email);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Пример #2
0
        public MembershipCreateStatus CreateUser(string nom, string prenom, string password, string email)
        {
            MembershipCreateStatus createStatus;

            try
            {
                // MembershipUser newuser  = Membership.CreateUser(email, password, email);
                MembershipUser newuser = Membership.CreateUser(email, password, email, passwordQuestion: null, passwordAnswer: null, isApproved: true,
                                                               providerUserKey: null, status: out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    using (toutokaz_dbEntities ctx = new toutokaz_dbEntities()){
                        tb_account p = new tb_account
                        {
                            id_user         = (Guid)newuser.ProviderUserKey,
                            firstname       = prenom,
                            lastname        = nom,
                            email           = email,
                            username        = email,
                            id_account_type = 1,
                            status          = "active",
                        };

                        ctx.tb_account.Add(p);
                        ctx.SaveChanges();
                    }
                }
            }
            catch (MembershipCreateUserException exp) {
                throw exp;
            }

            return(createStatus);
        }
Пример #3
0
        public string CreateUserPro(string nom, string prenom, string nom_entreprise, string password, string email)
        {
            string token = null;

            try
            {
                // create account and profile
                token = WebSecurity.CreateUserAndAccount(email, password, null, true);


                try
                {
                    Roles.AddUserToRole(email, "annonceur");
                }
                catch (System.Configuration.Provider.ProviderException exp)
                {
                    throw exp;
                }

                using (toutokaz_dbEntities ctx = new toutokaz_dbEntities())
                {
                    int        Id = WebSecurity.GetUserId(email);
                    tb_account p  = new tb_account
                    {
                        UserId          = Id,
                        firstname       = prenom,
                        lastname        = nom,
                        email           = email,
                        username        = email,
                        nom_entreprise  = nom_entreprise,
                        id_account_type = 2,
                        role            = "annonceur",
                        status          = "active",
                    };

                    ctx.tb_account.Add(p);
                    ctx.SaveChanges();
                }
            }
            catch (MembershipCreateUserException exp)
            {
                throw exp;
            }
            catch (InvalidOperationException exp)
            {
                throw exp;
            }

            return(token);
        }
Пример #4
0
        public MembershipCreateStatus CreateUserProMembership(string nom, string prenom, string nom_entreprise, string password, string email)
        {
            MembershipCreateStatus createStatus;

            try
            {
                // MembershipUser newuser  = Membership.CreateUser(email, password, email);
                MembershipUser newuser = Membership.CreateUser(email, password, email, passwordQuestion: null, passwordAnswer: null, isApproved: true,
                                                               providerUserKey: null, status: out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    try
                    {
                        Roles.AddUserToRole(newuser.UserName, "annonceur");
                    }
                    catch (System.Configuration.Provider.ProviderException exp)
                    {
                        throw exp;
                    }


                    using (toutokaz_dbEntities ctx = new toutokaz_dbEntities())
                    {
                        tb_account p = new tb_account
                        {
                            id_user         = (Guid)newuser.ProviderUserKey,
                            firstname       = prenom,
                            lastname        = nom,
                            email           = email,
                            username        = email,
                            nom_entreprise  = nom_entreprise,
                            id_account_type = 2,
                            role            = "annonceur",
                            status          = "active",
                        };

                        ctx.tb_account.Add(p);
                        ctx.SaveChanges();
                    }
                }
            }
            catch (MembershipCreateUserException exp)
            {
                throw exp;
            }

            return(createStatus);
        }
Пример #5
0
 public void Save()
 {
     _db.SaveChanges();
 }