Exemplo n.º 1
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

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

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (WebPagesContext db = new WebPagesContext())
                {
                    Webpages_UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        var newUser = new Webpages_UserProfile { UserName = model.UserName };
                        db.UserProfiles.Add(newUser);
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);
                        WebSecurity.CreateAccount(model.UserName, null);
                        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);
        }
Exemplo n.º 2
0
 public static Webpages_VUser CreateOrGetByUserId(int userid)
 {
     using (var db = new WebPagesContext())
     {
         var vuser = db.Webpages_VUsers.FirstOrDefault(o => o.UserID == userid);
         if (vuser != null)
             return vuser;
         if (db.UserProfiles.Find(userid) == null)
             return null;
         vuser = new Webpages_VUser();
         vuser.UserID = userid;
         vuser.Type = (int)VUserType.User;
         db.Webpages_VUsers.Add(vuser);
         db.SaveChanges();
         return vuser;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 保存 存有节点ID和本节点更改后的角色列表  信息 的Hashtable到数据库
        /// </summary>
        /// <param name="hstbl">存有节点ID和本节点更改后的角色列表  信息 的Hashtable</param>
        private static void SaveHashTableInfo(List<MenuNodeInfo> hstbl)
        {
            if (hstbl == null)
                return;

            using (var db = new WebPagesContext())
            {
                var tra = db.Database.Connection.BeginTransaction();
                try
                {

                    foreach (MenuNodeInfo item in hstbl)
                    {
                        int menuid = item.Nodeid;

                        foreach (int vuserid in item.AddedVUserids)
                        {
                            var right = db.MenuTreeRights.Find(menuid ,vuserid);
                            if (right == null)
                            {
                                right = new MenuTreeRight();
                                right.MenuId = menuid;
                                right.VuserID = vuserid;
                                db.MenuTreeRights.Add(right);
                            }

                        }
                        if (item.RemovedVUserids != null)
                        {
                            StringBuilder strDeleteVuserids = new StringBuilder();
                            foreach (int vuserid in item.RemovedVUserids)
                            {
                                var menu = db.MenuTrees.Find(menuid, vuserid);
                                db.Entry(menu).State = System.Data.EntityState.Deleted;
                            }

                        }
                    }
                    db.SaveChanges();
                    tra.Commit();
                }
                catch
                {
                    tra.Rollback();
                    throw;
                }
                finally
                {
                    db.Dispose();
                }
            }
        }
Exemplo n.º 4
0
 public static Webpages_VUser CreateOrGetByGroupId(string groupCode)
 {
     using (var db = new WebPagesContext())
     {
         var vuser = db.Webpages_VUsers.FirstOrDefault(o => o.RoleID == groupCode);
         if (vuser != null)
             return vuser;
         vuser = new Webpages_VUser();
         vuser.RoleID = groupCode;
         vuser.Type = (int)VUserType.Group;
         db.Webpages_VUsers.Add(vuser);
         db.SaveChanges();
         return vuser;
     }
 }