protected void Page_Load(object sender, EventArgs e) { String html = ""; String error = ""; html += "<div id=\"recover_container\"><form id=\"serviceRecover\" name=\"serviceRecover\" method=\"post\"><div class=\"login_form\">"; if (Session["user_info"] == null || !(Session["user_info"] is CASUserInfo)) { //Serviço não informado ou não encontrado html += " <ul>"; html += " <li><div class=\"error-box\">" + MessageResource.GetMessage("invalid_session") + "</div>"; html += " </ul>"; } else { CASUserInfo userInfo = (CASUserInfo)Session["user_info"]; using (DbBase db = DbBase.InstanceFromConfig(ConfigurationManager.ConnectionStrings["CASDatabase"])) { CASConnectorBase connector = CASUtils.GetService(db, this, userInfo.Service); if ((connector == null) || (connector is EmptyPlugin)) { //Serviço não informado ou não encontrado html += " <ul>"; html += " <li><div class=\"error-box\">" + MessageResource.GetMessage("service_invalid_uri") + "</div>"; html += " </ul>"; } if ((userInfo.RecoveryCode == null) || (String.IsNullOrEmpty((String)Session["userCode"]))) { html += " <ul>"; html += " <li><div class=\"error-box\">" + MessageResource.GetMessage("invalid_session") + "</div>"; html += " </ul>"; } else { if (Request.HttpMethod == "POST") { try { //String pwd = Session["atual_password"].ToString(); String password = Tools.Tool.TrataInjection(Request["password"]); String password2 = Request["password2"]; if ((password == null) || (password == "")) { error = MessageResource.GetMessage("type_password"); } else if ((password2 == null) || (password2 == "")) { error = MessageResource.GetMessage("type_password_confirm"); } else if (password != password2) { error = MessageResource.GetMessage("password_not_equal"); } else { CASChangePasswordResult res = connector.ChangePassword(userInfo, password); if (res.Success) { Response.Redirect(Session["ApplicationVirtualPath"] + "cas/passwordchanged/", false); return; } else { if (res.ErrorText == null) { throw new Exception(""); } error = res.ErrorText; } } } catch (Exception ex) { Tools.Tool.notifyException(ex); error = MessageResource.GetMessage("internal_error"); } } html += "<ul>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("new_password_title") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <input type=\"password\" id=\"password\" tabindex=\"1\" name=\"password\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password") + "\" onkeyup=\"cas.passwordStrength('#password');\" onfocus=\"$('#password').addClass('focus');\" onblur=\"$('#password').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <input type=\"password\" id=\"password2\" tabindex=\"1\" name=\"password2\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password_confirm") + "\" onfocus=\"$('#password2').addClass('focus');\" onblur=\"$('#password2').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password2').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <div id=\"passwordStrength\"><span>" + MessageResource.GetMessage("password_strength") + ": " + MessageResource.GetMessage("unknow") + "</span><div class=\"bar\"></div></div>"; html += " </li>"; if (error != "") { html += " <li><div class=\"error-box\">" + error + "</div>"; } html += " <li>"; html += " <span class=\"forgot\"> <a href=\"" + userInfo.Service.AbsoluteUri + "\">" + MessageResource.GetMessage("cancel") + "</a> " + MessageResource.GetMessage("or") + " </span>"; html += " <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("change_password") + "</button>"; html += " </li>"; html += "</ul> "; } } html += "</div>"; html += "</form>"; html += "</div>"; } holderContent.Controls.Add(new LiteralControl(html)); }
public CASChangePasswordResult iChangePassword(String userName, String password) { CASChangePasswordResult ret = new CASChangePasswordResult(false, userName); String lastStep = "Starting"; try { this.urlAPI = new Uri(Config["api"].ToString()); lastStep = "Get token"; APIAccessToken accessToken = new APIAccessToken(); accessToken.error = "Unknow error"; try { accessToken = GetToken(Config); } catch (Exception ex) { accessToken.error = "Erro on get Token: " + ex.Message; } lastStep = "Token check"; if ((accessToken != null) && (accessToken.IsValid)) { lastStep = "Serialize"; JavaScriptSerializer _ser = new JavaScriptSerializer(); String jData = ""; try { jData = _ser.Serialize(new { jsonrpc = "1.0", method = "user.changepassword", parameters = new { userid = Int64.Parse(userName), password = password, must_change = false }, auth = accessToken.Authorization, id = 1 }); } catch { jData = _ser.Serialize(new { jsonrpc = "1.0", method = "user.changepassword", parameters = new { user = userName, password = password, must_change = false }, auth = accessToken.Authorization, id = 1 }); } lastStep = "Auth"; APIUserChangePasswordResult jRet = JSON.JsonWebRequest <APIUserChangePasswordResult>(urlAPI, jData, "application/json", null, "POST"); lastStep = "Trata auth"; if (jRet == null) { ret.ErrorText = "Please enter a valid password"; } else if (jRet.error != null) { String add = ""; if (jRet.error.lowercase) { add += "Letra minúscula"; } if (jRet.error.uppercase) { if (add != "") { add += ", "; } add += "Letra maiúscula"; } if (jRet.error.number_char) { if (add != "") { add += ", "; } add += "Tamanho mínimo"; } if (jRet.error.numbers) { if (add != "") { add += ", "; } add += "Número"; } if (jRet.error.symbols) { if (add != "") { add += ", "; } add += "Simbolos"; } if (jRet.error.name_part) { if (add != "") { add += ", "; } add += "Não pode conter parte do nome"; } ret.ErrorText = jRet.error.data + add; } else if (jRet.result == null) { //Nda ret.ErrorText = "Please enter a valid password"; } else if (jRet.result.success) { ret.Success = true; } } else { ret.ErrorText = "Invalid token - API integration error" + (((accessToken != null) && (!String.IsNullOrEmpty(accessToken.error))) ? ": " + accessToken.error : ""); } } catch (Exception ex) { throw new Exception("Execution error. Last step = " + lastStep, ex); } return(ret); }
protected void Page_Load(object sender, EventArgs e) { String html = ""; String error = ""; html += "<div id=\"recover_container\"><form id=\"pwdChange\" name=\"pwdChange\" method=\"post\"><div class=\"login_form\">"; if ((Session["cas_ticket"] == null) || !(Session["cas_ticket"] is CASTicketResult)) { //Serviço não informado ou não encontrado html += " <ul>"; html += " <li><div class=\"error-box\">" + MessageResource.GetMessage("invalid_session") + "</div>"; html += " </ul>"; } else { CASTicketResult ticket = (CASTicketResult)Session["cas_ticket"]; using (DbBase db = DbBase.InstanceFromConfig(ConfigurationManager.ConnectionStrings["CASDatabase"])) { CASConnectorBase connector = CASUtils.GetService(db, this, ticket.Service); if ((connector == null) || (connector is EmptyPlugin)) { //Serviço não informado ou não encontrado html += " <ul>"; html += " <li><div class=\"error-box\">" + MessageResource.GetMessage("service_invalid_uri") + "</div>"; html += " </ul>"; } else if ((connector.State != null) && (connector.State is CASPluginService) && !(((CASPluginService)connector.State).Config.PermitChangePassword)) { CASPluginService p = (CASPluginService)connector.State; //Serviço não informado ou não encontrado html += " <ul>"; html += " <li><div class=\"error-box\">" + MessageResource.GetMessage("service_not_permit_change_pwd") + (!String.IsNullOrEmpty(p.Config.Admin) ? "<br /><br />" + p.Config.Admin : "") + "</div>"; html += " </ul>"; } else { if (Request.HttpMethod == "POST") { try { String password = Tools.Tool.TrataInjection(Request["password"]); String password2 = Request["password2"]; if ((password == null) || (password == "")) { error = MessageResource.GetMessage("type_password"); } else if ((password2 == null) || (password2 == "")) { error = MessageResource.GetMessage("type_password_confirm"); } else if (password != password2) { error = MessageResource.GetMessage("password_not_equal"); } else { CASChangePasswordResult res = connector.ChangePassword(ticket, password); if (res.Success) { connector.SaveTicket(ticket); CASUtils.AddCoockie(this, ticket); Session["user_info"] = new CASUserInfo(ticket); Response.Redirect(Session["ApplicationVirtualPath"] + "cas/passwordchanged/", false); return; } else { if (res.ErrorText == null) { throw new Exception(""); } error = res.ErrorText; } } } catch (Exception ex) { Tools.Tool.notifyException(ex); error = MessageResource.GetMessage("internal_error"); } } html += " <ul>"; html += " <li>"; html += " <p style=\"width:270px;padding:0 0 20px 0;color:#000;\">" + MessageResource.GetMessage("password_expired_text") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <input type=\"password\" id=\"password\" tabindex=\"1\" name=\"password\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password") + "\" onkeyup=\"cas.passwordStrength('#password');\" onfocus=\"$('#password').addClass('focus');\" onblur=\"$('#password').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <input type=\"password\" id=\"password2\" tabindex=\"1\" name=\"password2\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("new_password_confirm") + "\" onfocus=\"$('#password2').addClass('focus');\" onblur=\"$('#password2').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#password2').focus();\"></span>"; html += " </span>"; html += " </li>"; html += " <li>"; html += " <div id=\"passwordStrength\"><span>" + MessageResource.GetMessage("password_strength") + ": " + MessageResource.GetMessage("unknow") + "</span><div class=\"bar\"></div></div>"; html += " </li>"; if (error != "") { html += " <li><div class=\"error-box\">" + error + "</div>"; } html += " <li>"; html += " <span class=\"forgot\"> <a href=\"" + Session["ApplicationVirtualPath"] + "cas/login/?service=" + HttpUtility.UrlEncode(connector.Service.AbsoluteUri) + "\">" + MessageResource.GetMessage("cancel") + "</a> </span>"; html += " <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("change_password") + "</button>"; html += " </li>"; html += " </ul>"; } } html += "</div>"; html += "</form>"; html += "</div>"; } holderContent.Controls.Add(new LiteralControl(html)); }