Exemplo n.º 1
0
        public IActionResult recoveryPassword(string token)
        {
            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 tkn = new csgo.usersManager.recoveryPassword(token);

            if (tkn.verifyToken( ))
            {
                TempData["userId"] = tkn.userId;
                ViewBag.exist      = true;
            }
            return(View( ));
        }
Exemplo n.º 2
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")));
        }
Exemplo n.º 3
0
        public JsonResult resetPassApi(int userId)
        {
            string generatedToken = new csgo.usersManager.recoveryPassword(userId).addToken();

            return(Json(new { token = generatedToken }));
        }