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 { Session["userCode"] = null; CASUserInfo userInfo = (CASUserInfo)Session["user_info"]; html += "<ul>"; html += " <li class=\"title\">"; html += " <strong>" + MessageResource.GetMessage("password_changed_sucessfully") + "</strong>"; html += " </li>"; html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("password_changed_text") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"forgot\"> <a href=\"" + Session["ApplicationVirtualPath"] + "cas/login/?service=" + HttpUtility.UrlEncode(userInfo.Service.AbsoluteUri) + "\">" + MessageResource.GetMessage("return_default") + "</a></span>"; html += " </li>"; html += "</ul> "; } html += "</div>"; html += "</form>"; html += "</div>"; holderContent.Controls.Add(new LiteralControl(html)); }
public override CASUserInfo FindUser(String username) { CASUserInfo uInfo = new CASUserInfo(); //uInfo.ErrorText = "User not found"; uInfo.Success = false; uInfo.UserName = username; //uInfo.Emails.Add("*****@*****.**"); //uInfo.Emails.Add("*****@*****.**"); String lastStep = "Starting"; try { this.urlAPI = new Uri(Config["api"].ToString()); lastStep = "Get token"; APIAccessToken accessToken = GetToken(base.Config); lastStep = "Token check"; if ((accessToken != null) && (accessToken.IsValid)) { var loginRequest = new { jsonrpc = "1.0", method = "user.search", parameters = new { text = username, additional_field = "e-mail,email,login" }, auth = accessToken.Authorization, id = 1 }; lastStep = "Serialize"; JavaScriptSerializer _ser = new JavaScriptSerializer(); String jData = _ser.Serialize(loginRequest); lastStep = "User search"; APISearchResult jRet = JSON.JsonWebRequest <APISearchResult>(urlAPI, jData, "application/json", null, "POST"); lastStep = "Trata auth"; if (jRet == null) { uInfo.ErrorText = "User not found"; } else if (jRet.error != null) { uInfo.ErrorText = jRet.error.data; } else if (jRet.result == null) { //Nda uInfo.ErrorText = "User not found"; } else if (jRet.result.Count == 0) { uInfo.ErrorText = "User not found"; } else { lastStep = "Trata OK"; foreach (APIUserData uData in jRet.result) { if (uData.login == username) { //Resgata todas as informações deste usuário var userRequest = new { jsonrpc = "1.0", method = "user.get", parameters = new { userid = uData.userid }, auth = accessToken.Authorization, id = 1 }; lastStep = "Serialize 2"; jData = _ser.Serialize(userRequest); lastStep = "User request"; APIUserGetResult jRet2 = JSON.JsonWebRequest <APIUserGetResult>(urlAPI, jData, "application/json", null, "POST"); lastStep = "Trata User request"; if (jRet2 == null) { uInfo.ErrorText = "User not found"; } else if (jRet2.error != null) { uInfo.ErrorText = jRet2.error.data; } else if ((jRet2.result == null) || (jRet2.result.info == null)) { //Nda uInfo.ErrorText = "User not found"; } else if (jRet2.result.info.userid == 0) { uInfo.ErrorText = "User not found"; } else if ((jRet2.result.properties == null) || (jRet2.result.properties.Count == 0)) { uInfo.ErrorText = "User properties not found"; } else { foreach (APIUserDataProperty p in jRet2.result.properties) { if ((p.name.ToLower() == "email") || (p.name.ToLower() == "e-mail")) { if (!uInfo.Emails.Contains(p.value)) { uInfo.Emails.Add(p.value); } } } lastStep = "Trata OK 2"; uInfo.Success = true; } break; } } } } else { uInfo.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(uInfo); }
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\">"; Uri svc = null; try { svc = new Uri(Request.QueryString["service"]); } catch { } using (DbBase db = DbBase.InstanceFromConfig(ConfigurationManager.ConnectionStrings["CASDatabase"])) { CASConnectorBase connector = CASUtils.GetService(db, this, svc); 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.PermitPasswordRecover)) { 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_recover_pwd") + (!String.IsNullOrEmpty(p.Config.Admin) ? "<br /><br />" + p.Config.Admin : "") + "</div>"; html += " </ul>"; } else { //Caso a recuperação de senha seja externa, redireciona if ((connector.State is CASPluginService) && (((CASPluginService)connector.State).Config.ExternalPasswordRecover) && (((CASPluginService)connector.State).Config.PasswordRecoverUri != null)) { Response.Redirect(((CASPluginService)connector.State).Config.PasswordRecoverUri.AbsoluteUri, false); return; } Session["recover_service"] = svc.AbsoluteUri; if (Request.HttpMethod == "POST") { try { CASUserInfo user = connector.FindUser(Request["username"]); user.Service = connector.Service; if ((user.Success) && (user.Emails != null) && (user.Emails.Count > 0)) { user.NewCode(); Session["user_info"] = user; Response.Redirect("/cas/recover/step1/", false); return; } else if ((user.Emails == null) || (user.Emails.Count == 0)) { error = MessageResource.GetMessage("user_email_list"); } else { error = user.ErrorText; } } catch (Exception ex) { Tools.Tool.notifyException(ex); error = MessageResource.GetMessage("internal_error"); } } html += " <input type=\"hidden\" name=\"do\" value=\"recover1\" />"; html += " <ul>"; html += " <li>"; html += " <p style=\"width:270px;padding:0 0 20px 0;color:#000;\">" + MessageResource.GetMessage("login_recover_message") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; //html += " <span id=\"ph_userLogin\" class=\"noSel\" style=\"position: absolute; z-index: 1; top: 13px; left: 53px; color: rgb(204, 204, 204); display: block;\">" + MessageResource.GetMessage("login_user_name") + "</span>"; html += " <input type=\"text\" id=\"username\" tabindex=\"1\" name=\"username\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("login_user_name") + "\" onfocus=\"$('#userLogin').addClass('focus');\" onblur=\"$('#userLogin').removeClass('focus');\" />"; html += " <span id=\"ph_usernameIcon\" onclick=\"$('#userLogin').focus();\"></span>"; html += " </span>"; html += " </li>"; if (error != "") { html += " <li><div class=\"error-box\">" + error + "</div>"; } html += " <li>"; html += " <span class=\"forgot\"> <a href=\"" + svc.AbsoluteUri + "\">" + MessageResource.GetMessage("cancel") + "</a> " + MessageResource.GetMessage("or") + " </span>"; html += " <button tabindex=\"4\" id=\"submitBtn\" class=\"action button floatright\">" + MessageResource.GetMessage("login_recover_btn_recover") + "</button>"; html += " </li>"; html += " </ul> "; } html += "</div>"; html += "</form>"; html += "</div>"; } holderContent.Controls.Add(new LiteralControl(html)); }
public override CASChangePasswordResult ChangePassword(CASUserInfo user, String password) { return(iChangePassword(user.UserName, password)); }
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"]; if (Request.HttpMethod == "POST") { try { String sentTo = Request["sentTo"]; if ((sentTo == null) || (sentTo == "")) { error = MessageResource.GetMessage("select_option"); } else { if ((userInfo.Emails != null) && (userInfo.Emails.Count > 0)) { String emlSentTo = null; foreach (String eml in userInfo.Emails) { String data = Tools.Tool.MaskData(eml, true, false); if (sentTo.ToString().ToLower() == data) { emlSentTo = eml; break; } } if (emlSentTo == null) { error = MessageResource.GetMessage("option_not_found"); } else { Tools.Tool.sendEmail("Password recover code", emlSentTo, "Code: " + userInfo.RecoveryCode, false); Response.Redirect("/cas/recover/step2/", false); return; } } else { error = MessageResource.GetMessage("option_not_found"); } } } catch (Exception ex) { Tools.Tool.notifyException(ex); error = MessageResource.GetMessage("internal_error"); } } html += " <ul>"; if ((userInfo.Emails != null) && (userInfo.Emails.Count > 0)) { html += " <li>"; html += " <p style=\"width:100%;padding:0 0 5px 0;color:#000;\">" + MessageResource.GetMessage("send_conf_to") + "</p>"; html += " </li>"; foreach (String eml in userInfo.Emails) { String data = Tools.Tool.MaskData(eml, true, false); if (data != "") { html += " <li><p style=\"width:400px;padding:0 0 5px 10px;color:#000;\"><input name=\"sentTo\" type=\"radio\" value=\"" + data + "\">" + data + "</p></li>"; } } } else { error = "No method available"; } 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("login_recover_btn_recover") + "</button>"; html += " </li>"; html += " </ul> "; } html += "</div>"; html += "</form>"; html += "</div>"; holderContent.Controls.Add(new LiteralControl(html)); }
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"]; if (Request.HttpMethod == "POST") { try { String userCode = Request["userCode"]; if ((userCode == null) || (userCode == "")) { error = MessageResource.GetMessage("type_code"); } else { if (userCode.ToLower() == userInfo.RecoveryCode.ToLower()) { Session["userCode"] = userInfo.RecoveryCode; Response.Redirect("/cas/recover/step3/", false); return; } else { error = MessageResource.GetMessage("invalid_code"); } } } 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("enter_code") + "</p>"; html += " </li>"; html += " <li>"; html += " <span class=\"inputWrap\">"; html += " <input type=\"text\" id=\"userCode\" tabindex=\"1\" name=\"userCode\" value=\"\" style=\"\" placeholder=\""+ MessageResource.GetMessage("code") + "\" onfocus=\"$('#userCode').addClass('focus');\" onblur=\"$('#userCode').removeClass('focus');\" />"; html += " <span id=\"ph_passwordIcon\" onclick=\"$('#userCode').focus();\"></span>"; html += " </span>"; 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("confirm_code") + "</button>"; html += " </li>"; html += " </ul>"; } html += "</div>"; html += "</form>"; html += "</div>"; holderContent.Controls.Add(new LiteralControl(html)); }
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)); }
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)); }