Ejemplo n.º 1
0
        public JsonResult Login(UserLoginDTO userLogin)
        {
            if (!Global.Cache.CheckEmailExists(userLogin.UserName))
            {
                return(GetJson(EN_ErrorCodes.IncorrectLogin));
            }
            //
            UserLoginDetails UserLoginDetails = _DL.User.Account.LoginDetails_ByEmail(userLogin.UserName);

            //
            if (HashHMACSHA1.CheckSaltedHash(userLogin.Password, UserLoginDetails.PasswordHash))
            {
                var user = _DL.User.Get.ByID(UserLoginDetails.UserID);
                // Set User
                CurrentUser = user;
                // Set Log In
                Global.Cache.SetLogIn(user.UserID);
                //
                return(GetJson(new
                {
                    FirstName = user.UserFirstName,
                    LastName = user.UserLastName,
                    UserID = user.UserID,
                    AvatarSmall = user.AvatarSmall,
                    AvatarBig = user.AvatarBig
                }));
            }
            else
            {
                return(GetJson(EN_ErrorCodes.IncorrectPassword));
            }
        }
Ejemplo n.º 2
0
 public API_Response <VM_User> Login(DTO_UserLogin model)
 {
     return(InvokeAPI(() =>
     {
         VM_User user = null;
         if (!Global.Cache.CheckEmailExists(model.UserName))
         {
             throw new Exception("User Not Found");
         }
         //
         var UserLoginDetails = _DL.User.Account.LoginDetails_ByEmail(model.UserName);
         // Check User Login Details
         if (ModelState.IsValid)
         {
             // Check Password
             if (HashHMACSHA1.CheckSaltedHash(model.UserPassword, UserLoginDetails.PasswordHash))
             {
                 user = _DL.User.Get.ByID(UserLoginDetails.UserID);    // Get User
                 user.ApiKey = API_KeyHelper.GenarateKey(user.UserID); // Generate Token
             }
             else
             {
                 throw new Exception("Incorrect password");
             }
         }
         else
         {
             throw new Exception("Login Error");
         }
         return user;
     }, "", false));
 }
Ejemplo n.º 3
0
        public ActionResult LoginAndJoin(TagLoginAndJoinDTO model)
        {
            // Tag
            if (_DL.Tag.Get.ByID(model.TagID) == null)
            {
                return(RedirectToAction("TagNotFound", "Errors"));
            }
            // User
            if (_DL.User.Get.ByID(model.UserID) == null)
            {
                return(RedirectToAction("UserNotFound", "Errors"));
            }
            // Login Details
            var UserLoginDetails = _DL.User.Account.LoginDetails_ByEmail(model.Login);

            if (UserLoginDetails == null)
            {
                return(RedirectToAction("UserNotFound", "Errors"));
            }
            // login And Join
            if (ModelState.IsValid && UserLoginDetails.UserID >= 0)
            {
                if (HashHMACSHA1.CheckSaltedHash(model.Password, UserLoginDetails.PasswordHash))
                {
                    CurrentUser = _DL.User.Get.ByID(UserLoginDetails.UserID);
                    return(RedirectToAction("JoinToTag", "Tag", new { model.UserID, model.TagID }));
                }
            }
            return(RedirectToAction("IncorrectLogin", "Errors"));
        }