Ejemplo n.º 1
0
 public bool SendBindingParentRequest(User target, SmartRewardEntities db)
 {
     if (!Parents.Contains(target)
         && SendedNotifications.Where(n =>
             n.Receiver.UserId.Equals(target.UserId)
             && n.TypeNotificationCode == "BINDING_PARENT?"
             && n.Response == null)
             .ToList().Count == 0)
     {
         this.SendedNotifications.Add(new Notification { Sender = this, Receiver = target, TypeNotificationCode = "BINDING_PARENT?" });
         db.SaveChanges();
         return true;
     }
     return false;
 }
        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 (SmartRewardEntities db = new SmartRewardEntities())
                {
                    User user = db.Users.FirstOrDefault(u => u.Email.ToLower() == model.Email.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.Users.Add(new User { Email = model.Email });
                        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);
        }