Пример #1
0
 public void CreateUser(UserModels user)
 {
     var collection = database.GetCollection<UserModels>("users");
     //var findUser = collection.Find()
     collection.Insert<UserModels>(user);
 }
Пример #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                //MongoProvider provider = new MongoProvider();
                //bool loginSuccessful = true;// provider.ValidateUser(model.Email, model.Password);
                //if(loginSuccessful)
                //{
                //    SetAuthenticationCookie(model.Email);
                //    return RedirectToLocal(returnUrl);
                //}
                UserModels user = new UserModels
                {
                    email = model.Email,
                    password = Crypto.SHA1(model.Password)
                };
                if (db.Exist(user))
                {
                    LogOn(user.email);
                    return RedirectToLocal(returnUrl);
                }
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }
Пример #3
0
 public bool Exist(UserModels user)
 {
     var users = GetAllUsers();
     foreach (var item in users)
     {
         if (item.email == user.email && item.password == user.password)
             return true;
     }
     return false;
 }
Пример #4
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    UserModels user = new UserModels
                    {
                        email = model.Email,
                        password = Crypto.SHA1(model.Password),
                        listOfFavouriteObjects = new List<MongoDB.Bson.ObjectId>()
                    };
                    if (!db.Exist(user))
                        db.CreateUser(user);
                    LogOn(user.email);
                    return RedirectToAction("Map", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }