コード例 #1
0
 public static User GetSmartRewardUser(string userEmail, SmartRewardEntities db)
 {
     if (String.IsNullOrEmpty(userEmail))
     {
         return null;
     }
     try
     {
         return db.Users.SingleOrDefault(u => u.Email == userEmail);
     }
     catch
     {
         return null;
     }
 }
コード例 #2
0
 public static User GetSmartRewardUser(this System.Security.Principal.IPrincipal user, SmartRewardEntities db)
 {
     if (user == null || String.IsNullOrEmpty(user.Identity.Name))
     {
         return null;
     }
     try
     {
         return db.Users.SingleOrDefault(u => u.Email == user.Identity.Name);
     }
     catch
     {
         return null;
     }
 }
コード例 #3
0
ファイル: User.cs プロジェクト: BeardAnnihilator/SmartReward
 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;
 }
コード例 #4
0
        /// <summary>
        /// This method is called when the client connects to the hub (via javascript)
        /// </summary>
        /// <returns></returns>
        public override Task OnConnected()
        {
            string name = Context.User.Identity.Name;

            Groups.Add(Context.ConnectionId, name);

            SmartRewardEntities db = new SmartRewardEntities();
            User user = db.Users.Where(u => u.Email.Equals(name)).FirstOrDefault();
            if (user != null)
            {
                int unseenNotif = user.ReceivedNotifications.Where(n => !n.Seen).Count();
                if (unseenNotif > 0)
                    Notify(name, unseenNotif);
            }
            return base.OnConnected();
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<SmartRewardEntities>(null);

                try
                {
                    using (var context = new SmartRewardEntities())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("SmartRewardEntities", "Users", "UserId", "Email", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }
コード例 #6
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 (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);
        }