Ejemplo n.º 1
0
        public ActionResult Index(LesioBlog2_Repo.Models.User user)
        {
            //check if user is logged in
            bool isUserLogged = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;

            //nothing to post in displaying user state
            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult LogIn(LesioBlog2_Repo.Models.User user)
        {
            //got user with some details
            // if (ModelState.IsValid) --checking only email and password, not all
            {
                if (IsValid(user.Email, user.Password))
                {
                    //to get user nickname
                    FormsAuthentication.SetAuthCookie(_user.GetUserNicknameByEmail(user.Email), true);  //this decides which value goes to user.identiy name
                    return(RedirectToAction("Index", "Post"));
                }

                else
                {
                    ModelState.AddModelError("", "Login data is incorrect.");
                }
            }
            return(View(user));
        }
Ejemplo n.º 3
0
 public ActionResult Registration([Bind(Include = "Email,Password,User_Id,NickName,FullName,City,Gender_Id")] LesioBlog2_Repo.Models.User user)
 {
     //checking if email and nickname taken
     if (IsEmailUsernameTaken(user.Email, user.NickName))
     {
         if (ModelState.IsValid)  //password and email form checking
         {
             var crypto    = new SimpleCrypto.PBKDF2();
             var encrpPass = crypto.Compute(user.Password);
             user.Password     = encrpPass;
             user.PasswordSalt = crypto.Salt;
             //getting unique userID, checking with the database and repeating if userID selected
             //by random was not unique at all XD
             #region
             //userID
             var rnd = new Random();
             user.User_Id = rnd.Next();
             var matchingUser = _user.FindUserByID(user.User_Id);
             while (matchingUser != null)
             {
                 user.User_Id = rnd.Next();
                 matchingUser = _user.FindUserByID(user.User_Id);
             }
             //default values:
             user.Role_Id = 2; //default
             user.Active  = true;
             //deafult end
             #endregion
             _user.Add(user);
             _user.SaveChanges();
             return(RedirectToAction("LogIn", "User"));
         }
         else
         {
             ModelState.AddModelError("", "Regiser data is incorrect");
         }
     }
     else
     {
         ModelState.AddModelError("", "Email/Username taken, change it please");
     }
     return(View(user));
 }