Beispiel #1
0
 public void InsertOrUpdate(User user)
 {
     if (user.Id == default(int))
       {
     _db.Users.Add(user);
       }
       else
       {
     _db.Entry(user).State = EntityState.Modified;
       }
 }
        public ActionResult DoAuth(AuthType authType)
        {
            var authHandler =
            AuthHandlerFactory.CreateAuthHandler(authType);

              var userData =
            authHandler
              .ProcessAuthRequest(Request as HttpRequestWrapper);

              if (userData == null)
              {
            TempData["authError"] =
              Resources.SimpleAuth.LogIn.AuthenticationFailed;

            return
              RedirectToAction("LogIn");
              }

              var user =
            _userRepository
              .FindByClaimedId(
            userData.UserId,
            (AuthenticatedWith) authType);

              if (user == null)
              {
            user =
              new User
            {
              ClaimedId = userData.UserId,
              AuthenticatedWith = (int) authType,
              UserName = userData.UserName,
              PictureUrl = userData.PictureUrl
            };

            _userRepository
              .InsertOrUpdate(user);

            _userRepository.Save();
              }

              FormsAuthentication.SetAuthCookie(user.Id.ToString(), true);

              return
            Session["ReturnUrl"] != null
            ? (ActionResult) Redirect((string) Session["ReturnUrl"])
            : RedirectToAction("Index", "Events");
        }