Exemple #1
0
        public async Task <IActionResult> forgotPassword(csgo.postModels.forgotPassword obj)
        {
            if (csgo.Controllers.adminController.tokenAccess.validateToken(Request, adminController.tokenType.forgotpass))
            {
                if (csgo.core.requestsHelper.processRequest(Request))
                {
                    return(Json(new { success = "false", message = "You are sending to many requests. Blacklist will expire in 30 seconds." }));
                }

                bool exist = false; int id = -1; DateTime lastPasswordChange = DateTime.Now;
                await databaseManager.selectQuery("SELECT * FROM users WHERE email = @email LIMIT 1", delegate(DbDataReader reader)
                {
                    if (reader.HasRows)
                    {
                        id = ( int )reader["id"];
                        lastPasswordChange = ( DateTime )reader["lastChangedPassword"];
                        exist = true;
                    }
                }).addValue("@email", obj.email).Execute( );

                if (exist)
                {
                    if ((int)(DateTime.Now - lastPasswordChange).TotalHours < 2)
                    {
                        TempData["toast"] = "{type:'error',message:'You can reset your password once every 2 hours.'}";
                        return(this.Redirect(@Url.Action("index", "home")));
                    }
                    string token = new csgo.usersManager.recoveryPassword(id).addToken();
                    csgo.core.emailManager.sendRecoveryEmail(obj.email, token);
                    TempData["toast"] = "{type:'success',message:'An recovery link was sent to your email.'}";
                    return(this.Redirect(@Url.Action("index", "home")));
                }
                else
                {
                    TempData["toast"] = "{type:'error',message:'Email isn`t asocied to any account.'}";
                    return(this.Redirect(@Url.Action("lostPassword", "login")));
                }
            }

            TempData["toast"] = "{type:'error',message:'You are not authorized.'}";
            return(this.Redirect(@Url.Action("forgotPassword", "login")));
        }
Exemple #2
0
        public async Task <IActionResult> changeEmailPost(csgo.postModels.forgotPassword obj)
        {
            if (csgo.Controllers.adminController.tokenAccess.validateToken(Request, adminController.tokenType.changeemail))
            {
                if (csgo.core.requestsHelper.processRequest(Request))
                {
                    return(Json(new { success = "false", message = "You are sending to many requests. Blacklist will expire in 30 seconds." }));
                }
                var userId = TempData["userId"];
                if (userId == null)
                {
                    TempData["toast"] = "{type:'error',message:'You are not authorized. An error occured try again later 1.'}";
                    return(this.Redirect(@Url.Action("index", "home")));
                }
                if (obj.email.Contains("yahoo"))
                {
                    csgo.Controllers.adminController.tokenAccess.createToken(Request, adminController.tokenType.changeemail);
                    TempData["toast"]  = "{type:'error',message:'You can not use yahoo. Please use another mail service.'}";
                    TempData["userId"] = (int)userId;
                    return(this.Redirect(@Url.Action("changeEmail")));
                }
                if (await doesExist("email", obj.email))
                {
                    csgo.Controllers.adminController.tokenAccess.createToken(Request, adminController.tokenType.changeemail);
                    TempData["toast"]  = "{type:'error',message:'This email is already in use.'}";
                    TempData["userId"] = (int)userId;
                    return(this.Redirect(@Url.Action("changeEmail")));
                }


                string validateToken = csgo.core.emailManager.randomToken(new Random().Next(10, 30));
                Console.WriteLine(csgo.core.emailManager.sendConfirmationEmail(obj.email, validateToken).Content);
                await databaseManager.updateQuery($"UPDATE users SET lastConfirm = CURRENT_TIMESTAMP, email = @email, validateToken = @validateToken WHERE id = @id LIMIT 1").addValue("@validateToken", validateToken).addValue("@id", (int)userId).addValue("@email", obj.email).Execute();

                TempData["toast"] = "{type:'success',message:'And confirmation code was send to your new email.'}";
                return(this.Redirect(@Url.Action("index", "home")));
            }
            TempData["toast"] = "{type:'error',message:'You are not authorized 2.'}";
            return(this.Redirect(@Url.Action("index", "home")));
        }