protected void loginControl_LoggedIn(object sender, EventArgs e) { ProfilesMembershipUser user = (ProfilesMembershipUser)Membership.GetUser(((Login)sender).UserName); // Get an instance of the ProfileCommon object ProfileCommon p = (ProfileCommon)ProfileCommon.Create(user.UserName, true); // Set our parameters from the custom authentication provider p.UserId = user.UserID; p.UserName = user.UserName; p.HasProfile = user.HasProfile; p.ProfileId = user.ProfileID; p.DisplayName = user.DisplayName; // Persist the profile data p.Save(); // Refetch the profile data Profile.Initialize(user.UserName, true); //Profile.GetProfile(user.UserName); if (HttpContext.Current.Request.QueryString["EditMyProfile"] != null) { Response.Redirect("~/ProfileEdit.aspx?From=Self&Person=" + user.ProfileID.ToString()); } }
public void InitializeTest() { // Initializes the database with 10 sample users. for (int i = 1; i <= 10; i++) { ProfileCommon.Create("username" + i, true); } }
protected void buttonCreateUser_OnClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(tbCreateUser.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, "Feltet for bruker navn kan ikke være tomt"); return; } if (tbCreatePassword.Text.Length < Membership.Provider.MinRequiredPasswordLength) { Utils.displayStatus(ref labelStatus, Color.Red, "Passordet må ha minst " + Membership.Provider.MinRequiredPasswordLength.ToString() + " tegn"); return; } if (tbCreatePassword.Text != tbCreatePassword2.Text) { Utils.displayStatus(ref labelStatus, Color.Red, "Passordene er ikke like"); return; } try { MembershipCreateStatus status = new MembershipCreateStatus(); MembershipUser user = Membership.CreateUser(tbCreateUser.Text, tbCreatePassword.Text, "", "question", "answer", true, out status); if (user == null) { Utils.displayStatus(ref labelStatus, Color.Red, Utils.getErrorMessage(status)); return; } ProfileCommon prof = (ProfileCommon)ProfileCommon.Create(tbCreateUser.Text, true); if (prof == null) { Membership.DeleteUser(tbCreateUser.Text); Utils.displayStatus(ref labelStatus, Color.Red, "Oppretting av profil for bruker " + tbCreateUser.Text + " feilet"); return; } prof.Name = tbCreateName.Text; prof.Phone = tbCreatePhone.Text; prof.Email = tbCreateEmail.Text; prof.Title = tbCreateTitle.Text; prof.Save(); tbCreateUser.Text = ""; tbCreateName.Text = ""; tbCreatePhone.Text = ""; tbCreateEmail.Text = ""; tbCreateTitle.Text = ""; populateUserList(); Utils.displayStatus(ref labelStatus, Color.SeaGreen, "Bruker '" + user.UserName + "' opprettet"); } catch (Exception ex) { Utils.displayStatus(ref labelStatus, Color.Red, ex.Message); } }
protected void importBtn_Click(object sender, EventArgs e) { //at = SpringUtil.at(); String sql = "SELECT a.* , a.Param13+c.city+b.name as zipcht from ImportData a , zip b , QryCity c where a.Param13=b.id and a.Param12=c.pid"; //DataTable lists = new DataTable(); //at.DataTableFill(lists, CommandType.Text, sql); OleDbCommand cmd = new OleDbCommand(sql); DataSet ds = SQLUtil.QueryDS(cmd); //foreach (DataRow dRow in lists.Rows) foreach (DataRow dRow in ds.Tables[0].Rows) { MembershipUser user = Membership.CreateUser(dRow["Param1"].ToString(), dRow["Param2"].ToString(), dRow["Param8"].ToString(), dRow["Param9"].ToString(), dRow["Param9"].ToString(), true, out mc); user.Comment = dRow["Param3"].ToString(); Roles.AddUserToRole(dRow["Param1"].ToString(), "user"); Membership.UpdateUser(user); p = (ProfileCommon)ProfileCommon.Create(dRow["Param1"].ToString(), true); p.UserProfile.Owner = dRow["Param11"].ToString(); p.UserProfile.Name = dRow["Param5"].ToString(); p.UserProfile.Tel = dRow["Param6"].ToString(); p.UserProfile.Corp = dRow["Param3"].ToString(); p.UserProfile.City = dRow["Param12"].ToString(); p.UserProfile.Postcode = dRow["Param13"].ToString(); p.UserProfile.Address = dRow["Param4"].ToString(); p.UserProfile.Fax = dRow["Param7"].ToString(); p.UserProfile.Kind = dRow["Param10"].ToString(); p.UserProfile.Type = dRow["Param9"].ToString(); p.UserProfile.Zipcht = dRow["zipcht"].ToString(); p.Save(); UserProfiles up = new UserProfiles(); up.Username = dRow["Param1"].ToString(); up.Owner = dRow["Param11"].ToString(); up.Name = dRow["Param5"].ToString(); up.Tel = dRow["Param6"].ToString(); up.Corp = dRow["Param3"].ToString(); up.City = dRow["Param12"].ToString(); up.Postcode = dRow["Param13"].ToString(); up.Address = dRow["Param4"].ToString(); up.Fax = dRow["Param7"].ToString(); up.Kind = dRow["Param10"].ToString(); up.Type = dRow["Param9"].ToString(); up.Zipcht = dRow["zipcht"].ToString(); //mgr.Save(null, null, up); } }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); p.Name = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtName")).Text; p.BirthDate = DateTime.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtBirthDate")).Text); p.Save(); //Roles.AddUserToRole(CreateUserWizard1.UserName, "Authenticated"); }
private static Decimal GetTaxRate() { var profile = ProfileCommon.Create(HttpContext.Current.User.Identity.Name) as ProfileCommon; var currentState = new State(profile.BusinessAddress.BusinessState); var result = 0.0M; if (currentState.Taxable) { result = Decimal.Parse(currentState.TaxRate); } return(result); }
protected void RegisterUser_CreatedUser(object sender, EventArgs e) { ProfileCommon p = (ProfileCommon)ProfileCommon.Create((sender as CreateUserWizard).UserName, true); //FormsAuthentication.SetAuthCookie(RegisterUser.UserName,false /* createPersistentCookie */); //string continueUrl = RegisterUser.ContinueDestinationPageUrl; //if (String.IsNullOrEmpty(continueUrl)) //{ // continueUrl = "~/"; //} //Response.Redirect(continueUrl); }
protected void btnGadgetLogin_Click(object sender, EventArgs e) { // first look at password if (!ConfigUtil.GetConfigItem("OpenSocialDevPassword").Equals(txtPassword.Text)) { return; } String userName = null; try { Database db = DatabaseFactory.CreateDatabase(); string sqlCommand = "select username from [user] where UserID = " + Int32.Parse(txtPersonId.Text) + ";"; DbCommand dbCommand = db.GetSqlStringCommand(sqlCommand); userName = (String)db.ExecuteScalar(dbCommand); ProfilesMembershipUser user = (ProfilesMembershipUser)Membership.GetUser(userName); // Get an instance of the ProfileCommon object ProfileCommon p = (ProfileCommon)ProfileCommon.Create(user.UserName, true); // Set our parameters from the custom authentication provider p.UserId = user.UserID; p.UserName = user.UserName; p.HasProfile = user.HasProfile; p.ProfileId = user.ProfileID; p.DisplayName = user.DisplayName; // Persist the profile data p.Save(); // Refetch the profile data Profile.Initialize(user.UserName, true); //Profile.GetProfile(user.UserName); FormsAuthentication.SetAuthCookie(userName, false); // add the gadgets Session[OpenSocialHelper.OPENSOCIAL_GADGETS] = txtGadgetURLS.Text; Session[OpenSocialHelper.OPENSOCIAL_DEBUG] = chkDebug.Checked; Session[OpenSocialHelper.OPENSOCIAL_NOCACHE] = !chkUseCache.Checked; Response.Redirect("~/Search.aspx"); } catch (Exception ex) { // do nothing } }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { // Get the Profile of the newly created User ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); // User/Password has been created, populate the Profile Fields p.Name = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("NameTextBox")).Text; p.PhoneNumber = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("PhoneTextBox")).Text; p.HomeAddress = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("AddressTextBox")).Text; // Update the Profile p.Save(); // Add the User Role Roles.AddUserToRole(CreateUserWizard1.UserName, "user"); }
public RegistrationResponse RegisterUser(RegistrationRequest request) { RegistrationResponse response = new RegistrationResponse(); response.success = false; MembershipCreateStatus status; // create user and auto-approve // NOTE: optionally require e-mail account validation // to activate / approve user MembershipUser user = Membership.Provider.CreateUser( request.username, request.pwd, request.email, null, null, true, null, out status); if (status == MembershipCreateStatus.Success) { response.success = true; // validate / login users if (Membership.ValidateUser(request.username, request.pwd)) { // set authentication cookie FormsAuthentication.SetAuthCookie(request.username, request.createCookie); // Create an empty Profile for the newly created user ProfileCommon p = (ProfileCommon)ProfileCommon.Create(request.username, true); // store salt p.Salt = request.salt; p.Save(); try { // send email SendRegistrationMail(request.email, request.username); response.email_sent = true; } catch (Exception e) { response.email_sent = false; } } } response.message = status.ToString(); return(response); }
public void CheckOrGenerateAdministrator() { string username = "******"; string password = "******"; MembershipUserCollection listOfUserNameByName = Membership.FindUsersByName(username); if (listOfUserNameByName.Count == 0) { MembershipUser m = Membership.CreateUser(username, password); ProfileCommon.Create(username).Save(); ProfileCommon p = ProfileCommon.GetProfile(username); p.RoleID = (int)PermissionType.Administrator; p.IsActive = true; p.Save(); new UserProfileBFC().Create(username, "System"); } }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup RJS.Web.WebControl.PopCalendar.JavaScriptCustomPath = "~/App_Scripts/PopCalendar"; IgrssCommon.SetConnectionString("IGRSS_FINALConnectionString", ConfigurationManager.ConnectionStrings["IGRSS_FINALConnectionString"].ConnectionString); IgrssCommon.SetConnectionString("IGRSS_DEVConnectionString", ConfigurationManager.ConnectionStrings["WorkflowConnection"].ConnectionString); MembershipCreateStatus CreateUser = new MembershipCreateStatus(); Membership.CreateUser("admin", "admin", "*****@*****.**", "admin", "admin", true, out CreateUser); ProfileCommon UserProfile = (ProfileCommon)ProfileCommon.Create("admin"); XmlDocument xmlDoc = new XmlDocument(); string XmlFilePath = "~/XMLFile.xml"; xmlDoc.Load(Server.MapPath(XmlFilePath)); UserProfile.Permissions.MenuItems = xmlDoc.OuterXml; UserProfile.Save(); }
protected void Page_Load(object sender, EventArgs e) { ProfileCommon loginProfile; String result = "0"; // Return 0 if authentication failure // Arguments can be passed either by get or by post String username = Request["user"]; String password = Request["pass"]; // If valid, get the employee number and generate the random number if (Membership.ValidateUser(username, password)) { // Get the Profile of the User loginProfile = (ProfileCommon)ProfileCommon.Create(username, true); result = AndroidAuthenticationController.GenerateAndroidSessionNumber(loginProfile.EmpNo).ToString(); } Response.Write(result); }
private MembershipCreateStatus GenerateAccount(String username, String password, String employeeID) { // Create Login MembershipCreateStatus result; MembershipUser newUser = Membership.CreateUser(username, password, "", "?", "!", true, out result); if (result == MembershipCreateStatus.Success) { // Get the Profile of the newly created User ProfileCommon p = (ProfileCommon)ProfileCommon.Create(username, true); // TODO : CHECK IF EMPLOYEE NUMBER EXISTS p.EmpNo = Convert.ToInt32(employeeID); // Update The Profile p.Save(); } return(result); }
public WCFSessionID AuthenticateUser(String username, String password) { ProfileCommon loginProfile; WCFSessionID result = new WCFSessionID() { SessionID = "0" }; if (Membership.ValidateUser(username, password)) { // Update the roles of the logged in user LoginController.setupRolesAfterAuthentication(username); // Get the Profile of the User loginProfile = (ProfileCommon)ProfileCommon.Create(username, true); result.SessionID = AndroidAuthenticationController.GenerateAndroidSessionNumber(loginProfile.EmpNo).ToString(); } return(result); }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { try { CreateUserWizard1.UserName = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("UserName")).Text; user = Membership.GetUser(CreateUserWizard1.UserName); user.ChangePasswordQuestionAndAnswer(user.GetPassword(), "2", "2"); user.IsApproved = false; user.Comment = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Corp")).Text; Roles.AddUserToRole(CreateUserWizard1.UserName, "user"); Membership.UpdateUser(user); p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); p.UserProfile.Name = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; p.UserProfile.Owner = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Owner")).Text; p.UserProfile.Tel = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Tel")).Text; p.UserProfile.Corp = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Corp")).Text; p.UserProfile.City = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedValue; p.UserProfile.Postcode = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue; p.UserProfile.Address = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Address")).Text; p.UserProfile.Fax = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Fax")).Text; p.UserProfile.Kind = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("Kind")).SelectedValue; p.UserProfile.Type = "2"; p.UserProfile.Zipcht = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedItem.Text + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedItem.Text; p.Save(); ReuseTech obj = new ReuseTech(); obj.Username = CreateUserWizard1.UserName; obj.Techitem = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("TechItem")).SelectedValue; if (!obj.Techitem.Equals("V")) { obj.Techother = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("TechItem")).SelectedItem.Text; } else { obj.Techother = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("TechOther")).Text; } obj.Techname = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("TechName")).Text; obj.Wasteitem = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("WasteItem")).SelectedValue; if (!obj.Wasteitem.Equals("U")) { obj.Wasteother = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("WasteItem")).SelectedItem.Text; } else { obj.Wasteother = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("WasteOther")).Text; } obj.Wastename = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("WasteName")).Text; obj.Reusename = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("ReuseName")).Text; //obj.Researchitem = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("ResearchItem")).SelectedValue; //obj.Patent = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Patent")).Text; //obj.Techadv = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("TechAdv")).Text; //obj.Techdesc = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("TechDesc")).Text; obj.Type = "2"; obj.Isapproved = false; obj.Createdate = DateTime.Now; obj.Researchitem = ""; obj.Patent = ""; obj.Techadv = ""; obj.Techdesc = ""; /* UserProfiles */ UserProfiles up = new UserProfiles(); up.Username = CreateUserWizard1.UserName; up.Owner = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; up.Name = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; up.Tel = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Tel")).Text; up.Corp = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Corp")).Text; up.City = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedValue; up.Postcode = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue; up.Address = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Address")).Text; up.Fax = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Fax")).Text; up.Kind = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("Kind")).SelectedValue; up.Type = "2"; up.Zipcht = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedItem.Text + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedItem.Text; /* 配對 */ //at = SpringUtil.at(); String sql = "SELECT * FROM ReuseTech "; sql += " WHERE type='1' and ((TechOther like @param1) or (WasteOther like @param2) or (TechName like @param3) or (WasteName like @param4)) "; //IDbParameters parameters = at.CreateDbParameters(); //parameters.Add("param1", OleDbType.VarChar).Value = obj.Techother; //parameters.Add("param2", OleDbType.VarChar).Value = obj.Wasteother; //parameters.Add("param3", OleDbType.VarChar).Value = "%" + obj.Techname + "%"; //parameters.Add("param4", OleDbType.VarChar).Value = "%" + obj.Wastename + "%"; //DataSet ds = new DataSet(); //at.DataSetFillWithParameters(ds, CommandType.Text, sql, parameters); OleDbCommand cmd = new OleDbCommand(sql); cmd.Parameters.Add("param1", OleDbType.VarChar).Value = obj.Techother; cmd.Parameters.Add("param2", OleDbType.VarChar).Value = obj.Wasteother; cmd.Parameters.Add("param3", OleDbType.VarChar).Value = "%" + obj.Techname + "%"; cmd.Parameters.Add("param4", OleDbType.VarChar).Value = "%" + obj.Wastename + "%"; cmd.CommandType = CommandType.Text; DataSet ds = SQLUtil.QueryDS(cmd); ArrayList matchList = new ArrayList(); foreach (DataRow dRow in ds.Tables[0].Rows) { Match match = new Match(); user2 = Membership.GetUser(dRow["UserName"].ToString()); p2 = (ProfileCommon)ProfileCommon.Create(dRow["UserName"].ToString(), true); match.Username2 = CreateUserWizard1.UserName; match.Username1 = dRow["UserName"].ToString(); match.Rid1 = (int)dRow["Id"]; match.Name2 = p.UserProfile.Name; match.Name1 = p2.UserProfile.Name; match.Corp2 = p.UserProfile.Corp; match.Corp1 = p2.UserProfile.Corp; match.Tel2 = p.UserProfile.Tel; match.Tel1 = p2.UserProfile.Tel; match.Wasteitem2 = obj.Wasteother; match.Wasteitem1 = dRow["WasteOther"].ToString(); match.Wastename2 = obj.Wastename; match.Wastename1 = dRow["WasteName"].ToString(); match.Techitem2 = obj.Techother; match.Techitem1 = dRow["TechOther"].ToString(); match.Techname2 = obj.Techname; match.Techname1 = dRow["TechName"].ToString(); match.Reusename2 = obj.Reusename; match.Reusename1 = dRow["ReuseName"].ToString(); match.Matchdate = DateTime.Now; match.Ischecked = "A"; match.Isdeleted = false; match.Isconfirm2 = "A"; match.Isconfirm1 = "A"; match.Isdroped2 = "A"; match.Isdroped1 = "A"; match.Createdate2 = DateTime.Now; match.Createdate1 = (DateTime)dRow["Createdate"]; match.Isapproved2 = false; if (user2 != null) { if (user2.IsApproved) { match.Isapproved1 = true; } else { match.Isapproved1 = false; } } else { match.Isapproved1 = false; } match.Techdesc = dRow["TechDesc"].ToString(); match.Techadv = dRow["TechAdv"].ToString(); matchList.Add(match); } Save(obj, matchList, up); //mgr.Save(obj, matchList, up); ((Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("Msg")).Text = "您的帳號申請資料已經送出,請等待審核通知。"; #region Email /* Mail */ /* to 會員 */ //Marquee objM = mgrM.getMarquee("B"); String sqlMarquee = "SELECT * from Marquee where Id=? "; OleDbCommand cmdM = new OleDbCommand(sqlMarquee); cmdM.Parameters.Add("?", OleDbType.VarChar).Value = "B"; cmdM.CommandType = CommandType.Text; DataSet dsm = SQLUtil.QueryDS(cmdM); string strEmailMsg = ""; foreach (DataRow dr in dsm.Tables[0].Rows) { strEmailMsg = dr["Msg"].ToString(); } SmtpClient sc = new SmtpClient("smtp.tgpf.org.tw"); sc.Credentials = new System.Net.NetworkCredential("*****@*****.**", "IDB.riw@2018"); string strMsg = ""; string strTo = ""; string strFrom = ""; string strSubject = "資源化技術研發供需資訊平台通知"; //strMsg += "帳號: " + CreateUserWizard1.UserName + "\n"; //strMsg += "單位: " + p.UserProfile.Corp + "\n"; //strMsg += "會員姓名: " + p.UserProfile.Name + "\n"; //strMsg += "Email: " + ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Email")).Text + "\n"; strMsg += "<p>" + p.UserProfile.Name + " 先生/小姐您好</p>"; strMsg += "<p>感謝您加入「資源化技術研發供需資訊平台」 會員!!</p>"; strMsg += "<p>目前正在審核您的會員資料,造成不便敬請見諒。</p>"; strMsg += "<p>待審核後系統將主動通知您審核結果,</p>"; strMsg += "<p>通過審核後即可再次登入「資源化技術研發供需資訊平台」,</p>"; strMsg += "<p>獲得平台所提供的相關功能與服務!</p><br/><br/>"; strMsg += "<p>此信件為系統自動發送,請勿直接回覆,謝謝。</p>"; MembershipUser mng = Membership.GetUser("isrmng"); strFrom = mng.Email; strTo = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Email")).Text; //try //{ MailMessage msgMail = new MailMessage(strFrom, strTo); msgMail.Subject = strSubject; msgMail.IsBodyHtml = true; msgMail.Body = strMsg; msgMail.CC.Add("*****@*****.**"); new util().SendMail(strFrom, strTo, strSubject, strMsg, "*****@*****.**"); /* to Manager */ strSubject = "資源化技術研發供需資訊平台-新增會員通知"; strMsg = "<p>業者廠商</p>"; strMsg += "<p>單位名稱:" + p.UserProfile.Corp + "</p>"; strMsg += "<p>聯絡人:" + p.UserProfile.Name + "</p>"; strMsg += "<p>地址:" + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedItem.Text + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedItem.Text + ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Address")).Text + "</p>"; strMsg += "<p>電話:" + ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Tel")).Text + "</p>"; if (strEmailMsg.Length > 0) { strMsg += "<p><a href=\"" + strEmailMsg + "\">" + strEmailMsg + "</a></p>"; } //strMsg += "<p><a href=\"" + objM.Msg + "\">" + objM.Msg + "</a></p>"; strTo = mng.Email; msgMail = new MailMessage(strFrom, strTo); msgMail.Subject = strSubject; msgMail.IsBodyHtml = true; msgMail.Body = strMsg; msgMail.CC.Add("*****@*****.**"); new util().SendMail(strFrom, strTo, strSubject, strMsg, "*****@*****.**"); /* Mail End */ //} //catch //{ // ((Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("Msg")).Text = "您的帳號申請資料已經送出,請等待審核通知。<br/>錯誤:信件寄送失敗 "; //} #endregion } catch (Exception err) { Membership.DeleteUser(CreateUserWizard1.UserName, true); String strDelReuseTech = "delete from ReuseTech where UserName = @username"; OleDbCommand cmdDelReuseTech = new OleDbCommand(strDelReuseTech); cmdDelReuseTech.Parameters.Add("@username", OleDbType.VarChar).Value = CreateUserWizard1.UserName; cmdDelReuseTech.CommandType = CommandType.Text; SQLUtil.ExecuteSql(cmdDelReuseTech); String strDelUserProfile = "delete from UserProfiles where UserName = @username"; OleDbCommand cmdDelUserProfile = new OleDbCommand(strDelUserProfile); cmdDelUserProfile.Parameters.Add("@username", OleDbType.VarChar).Value = CreateUserWizard1.UserName; cmdDelUserProfile.CommandType = CommandType.Text; SQLUtil.ExecuteSql(cmdDelUserProfile); ((Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("Msg")).Text = "錯誤: " + err.ToString(); } }
protected void Button1_Click(object sender, EventArgs e) { int i = 0; string RandomKey = null; KeyGen = new KeyGenerate(); KeyGen.KeyLetters = "abcdefghjklmnpqrstuvwxyz"; KeyGen.KeyNumbers = "23456789"; KeyGen.KeyChars = 9; int mExist = 0; int mExist1 = 0; for (i = 0; i <= 1; i++) { RandomKey = KeyGen.Generate().ToUpper(); } if (RadioButtonList1.SelectedItem.Value == "1") { MembershipUser mem = Membership.GetUser(TextBox1.Text); if (mem == null) { MembershipCreateStatus status; MembershipUser newuser = Membership.CreateUser(TextBox1.Text, RandomKey, TextBox1.Text, "a", "a", true, out status); if (newuser == null) { msg.Show(GetErrorMessage(status)); } else { ProfileCommon pc = (ProfileCommon)ProfileCommon.Create(TextBox1.Text, true); Roles.AddUserToRole(TextBox1.Text, "user"); mailing mail = new mailing(); mail.mymail(TextBox1.Text, "Dear customer, you are successfully registered with ZartShop.com. Account details are as follows <br/>UserName : "******"<br>Password : "******"<br/><br/>Regards,<br/>ZartShop.com", "ZartShop Registration"); msg.Show("Registered successfully"); newsletter.addnewsletter(TextBox1.Text); System.Threading.Thread.Sleep(1000); FormsAuthentication.SetAuthCookie(TextBox1.Text, true); Response.Redirect("shipping-address.aspx?id=" + RadioButtonList1.SelectedItem.Value.ToString()); } } else { msg.Show("Email Id already registered"); } } else { DataTable dt = ad.checkuser(TextBox1.Text, TextBox2.Text); if (dt.Rows.Count == 0) { msg.Show("Invalid username and password"); } else { if (Request.QueryString["returnurl"] != null) { string te1 = Request.QueryString["returnurl"].ToString(); try { FormsAuthentication.SetAuthCookie(TextBox1.Text, true); Response.Redirect(te1); } catch (Exception ex) { } } else { string te = "shipping-address.aspx?id=" + RadioButtonList1.SelectedItem.Value.ToString(); FormsAuthentication.SetAuthCookie(TextBox1.Text, true); Response.Redirect(te); } } } }
protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e) { try { CreateUserWizard1.UserName = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("UserName")).Text; user = Membership.GetUser(CreateUserWizard1.UserName); user.ChangePasswordQuestionAndAnswer(user.GetPassword(), "1", "1"); user.IsApproved = true; user.Comment = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Corp")).Text; Roles.AddUserToRole(CreateUserWizard1.UserName, "user"); Membership.UpdateUser(user); p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); p.UserProfile.Owner = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; p.UserProfile.Name = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; p.UserProfile.Tel = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Tel")).Text; p.UserProfile.Corp = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Corp")).Text; p.UserProfile.City = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedValue; p.UserProfile.Postcode = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue; p.UserProfile.Address = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Address")).Text; p.UserProfile.Fax = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Fax")).Text; p.UserProfile.Kind = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("Kind")).SelectedValue; p.UserProfile.Type = "1"; p.UserProfile.Zipcht = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedItem.Text + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedItem.Text; p.Save(); /* UserProfiles */ UserProfiles up = new UserProfiles(); up.Username = CreateUserWizard1.UserName; up.Owner = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; up.Name = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Name")).Text; up.Tel = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Tel")).Text; up.Corp = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Corp")).Text; up.City = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedValue; up.Postcode = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue; up.Address = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Address")).Text; up.Fax = ((TextBox)UserTemplate.ContentTemplateContainer.FindControl("Fax")).Text; up.Kind = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("Kind")).SelectedValue; up.Type = "1"; up.Zipcht = ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedValue + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("cityList")).SelectedItem.Text + ((DropDownList)UserTemplate.ContentTemplateContainer.FindControl("zipList")).SelectedItem.Text; String sqlUp = ""; sqlUp = sqlUp + " insert into UserProfiles ([address],[city],[corp],[fax] ,[kind],[name],[owner],[postcode],[tel],[type],[username],[zipcht]) "; sqlUp = sqlUp + " values (@address,@city,@corp,@fax ,@kind,@name,@owner,@postcode,@tel,@type,@username,@zipcht)"; //sqlUp = sqlUp + " insert into UserProfiles ([address],[city],[corp],[fax],[kind],[name],[owner],[postcode],[tel],[type],[username],[zipcht]) "; //sqlUp = sqlUp + " values (@address,@city,@corp,@fax,@kind,@name,@owner,@postcode,@tel,@type,@username,@zipcht) "; OleDbCommand cmdM = new OleDbCommand(sqlUp); cmdM.Parameters.Add("@address", OleDbType.VarChar).Value = up.Address; cmdM.Parameters.Add("@city", OleDbType.VarChar).Value = up.City; cmdM.Parameters.Add("@corp", OleDbType.VarChar).Value = up.Corp; cmdM.Parameters.Add("@fax", OleDbType.VarChar).Value = up.Fax; cmdM.Parameters.Add("@kind", OleDbType.VarChar).Value = up.Kind; cmdM.Parameters.Add("@name", OleDbType.VarChar).Value = up.Name; cmdM.Parameters.Add("@owner", OleDbType.VarChar).Value = up.Owner; cmdM.Parameters.Add("@postcode", OleDbType.VarChar).Value = up.Postcode; cmdM.Parameters.Add("@tel", OleDbType.VarChar).Value = up.Tel; cmdM.Parameters.Add("@type", OleDbType.VarChar).Value = up.Type; cmdM.Parameters.Add("@username", OleDbType.VarChar).Value = up.Username; cmdM.Parameters.Add("@zipcht", OleDbType.VarChar).Value = up.Zipcht; cmdM.CommandType = CommandType.Text; //SQLUtil.ExecuteSql(cmdM); object objUserProfile = SQLUtil.ExecuteScalar(cmdM); //mgr.Save(null, null, up); ((Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("Msg")).Text = "學研機構會員新增完成。"; } catch (Exception err) { Membership.DeleteUser(CreateUserWizard1.UserName, true); ((Label)CompleteWizardStep1.ContentTemplateContainer.FindControl("Msg")).Text = "錯誤: " + err.ToString(); } }
public string GetErrorMessage(MembershipCreateStatus status) { switch (status) { case MembershipCreateStatus.DuplicateUserName: return("Username already exists. Please enter a different user name."); case MembershipCreateStatus.DuplicateEmail: return("A username for that e-mail address already exists. Please enter a different e-mail address."); case MembershipCreateStatus.InvalidPassword: return("Password should be of minimum of 6 characters and should be alphanumeric"); case MembershipCreateStatus.InvalidEmail: return("The e-mail address provided is invalid. Please check the value and try again."); case MembershipCreateStatus.InvalidAnswer: return("The password retrieval answer provided is invalid. Please check the value and try again."); case MembershipCreateStatus.InvalidQuestion: return("The password retrieval question provided is invalid. Please check the value and try again."); case MembershipCreateStatus.InvalidUserName: return("The user name provided is invalid. Please check the value and try again."); case MembershipCreateStatus.ProviderError: return("The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."); case MembershipCreateStatus.UserRejected: return("The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."); case MembershipCreateStatus.Success: ProfileCommon pc = (ProfileCommon)ProfileCommon.Create(Username.Text, true); Roles.AddUserToRole(Username.Text, "user"); pc.FirstName = firstname.Text; pc.Phone = phone.Text; pc.Mobile = mobile.Text; pc.Address = address1.Text; pc.City = DropDownList1.SelectedItem.Text; pc.State = Region.Text; pc.Save(); mailing mail = new mailing(); string msg1 = "Congratulations you are registered successfully with Fresh Farm Prawns" + "<br>" + "Username: "******"<br>" + "Password: "******"<br>" + "Regards ," + "<br>" + "Admin" + ", " + "Fresh Farm Prawns"; mail.mymail(Email.Text, msg1, "User Registration"); sms s = new sms(); s.SendSMS(mobile.Text, "Dear " + firstname.Text + " your freshprawnsonline account has been created. Username:"******" Password:"******""; //Password.Text = ""; //Repassword.Text = ""; //firstname.Text = ""; //address1.Text = ""; //DropDownList1.SelectedIndex = 0; //Region.Text = ""; //Email.Text = ""; //mobile.Text = ""; //phone.Text = ""; //CheckBox2.Checked = false; // address1.Text = city.Text = answer.Text = Region.Text = Email.Text = firstname.Text = lastname.Text = phone.Text = mobile.Text = Username.Text = ""; return("Registered Successfully"); default: return("An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."); } }
private void SaveProfile(string username) { ProfileCommon p = (ProfileCommon)ProfileCommon.Create(username, true); Profile.FirstName = txtFirstName.Text; Profile.LastName = txtLastName.Text; Profile.Address = txtAddress.Text; Profile.City = txtCity.Text; Profile.PostalCode = txtZipcode.Text; Profile.State = txtState.Text; Profile.Country = "USA"; Profile.Save(); MembershipUser myObject = Membership.GetUser(username); if (chckCopyPermission.Checked) { var uName = ddlUserList.SelectedItem.Value; DataSet userRight = FormRightsManager.GetFormByUserID(uName); foreach (DataRow dr in userRight.Tables[0].Rows) { var chkInsertRight = bool.Parse(dr["InsertRight"].ToString()); var chkUpdateRight = bool.Parse(dr["UpdateRight"].ToString()); var chkDeleteRight = bool.Parse(dr["DeleteRight"].ToString()); var chkSelectRight = bool.Parse(dr["SelectRight"].ToString()); var FormID = int.Parse(dr["FormID"].ToString()); FormRights fright = new FormRights(); fright.UserID = myObject.ProviderUserKey.ToString(); fright.FormID = FormID; fright.SelectRight = chkSelectRight; fright.InsertRight = chkInsertRight; fright.UpdateRight = chkUpdateRight; fright.DeleteRight = chkDeleteRight; bool result = FormRightsManager.UpdateFormRights(fright); } } else { var chkInsertRight = false; var chkUpdateRight = false; var chkDeleteRight = false; var chkSelectRight = false; DataSet formName = FormsManager.GetAllFormss(); foreach (DataRow dr in formName.Tables[0].Rows) { FormRights fright = new FormRights(); fright.UserID = myObject.ProviderUserKey.ToString(); fright.FormID = int.Parse(dr["FormsID"].ToString());; fright.SelectRight = chkSelectRight; fright.InsertRight = chkInsertRight; fright.UpdateRight = chkUpdateRight; fright.DeleteRight = chkDeleteRight; bool result = FormRightsManager.UpdateFormRights(fright); } } }
protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e) { // Have we JUST reached the Complete step? if (CreateUserWizard1.ActiveStep.Title != "Complete") { return; } // add newly created user to default Role specified above if (Roles.RoleExists(wsatDefaultRole)) { // Add the newly created user to the default Role. Roles.AddUserToRole(CreateUserWizard1.UserName, wsatDefaultRole); // Create an empty Profile for the newly created user ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true); // Populate some Profile properties. Values are located in web.config file //p.Company.Company = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeName")).Text; //p.Company.Address = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeAddress")).Text; //p.Company.City = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeCity")).Text; //p.Company.State = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlStates")).SelectedValue; //p.Company.PostalCode = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeZip")).SelectedValue; //p.Company.PostalCode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbOfficeZip")).Text; //p.Company.Phone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactPhone")).Text; //p.Company.Fax = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbContactFax")).Text; //p.Preferences.Newsletter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ddlNewsletter")).SelectedValue; //p.Personal.FirstName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbFirstName")).Text; //p.Personal.LastName = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbLastName")).Text; //p.Contacts.CellPhone = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txbPhone")).Text; // Save profile - must be done since we explicitly created it p.Save(); SendEmail(); } else { // Show the error message InvalidUserNameOrPasswordMessage.Text = "Oops! The default Role does not exist for this site.<br/>The site administrator has been contacted and made aware of this error..."; InvalidUserNameOrPasswordMessage.Visible = true; // notify administrator via email try { // get default email address from web.config string AdminEmail = ConfigurationManager.AppSettings["AdminEmail"]; string emailToWebConfig = AdminEmail.ToString(); // create timestamp string timeStamp = DateTime.Now.ToString("F"); // send mail System.Net.Mail.MailMessage MyMailer = new System.Net.Mail.MailMessage(); MyMailer.To.Add(emailToWebConfig); MyMailer.From = new MailAddress(wsatDefaultRoleMissing, "Missing Default Role Notification"); MyMailer.Subject = "Missing Default Role Notification"; MyMailer.Body = "Dear Site Administrator, <br/><br/> You have recieved a Missing Default Role Notification. <br/> Please remember to remedy the problem.</b><br/>"; MyMailer.Body += "time of occurance: " + timeStamp; MyMailer.Body += "<br/><br/><b>Have a wonderful day!"; MyMailer.IsBodyHtml = true; MyMailer.Priority = MailPriority.High; SmtpClient client = new SmtpClient(); client.Send(MyMailer); } catch { // do nothing } } }
private void TestMembershipAPI() { try { // Test Membership API try { var newUser = Membership.CreateUser(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); } catch (Exception x) { MarkAsFail(MembershipLabel, x.Message, "Probably wrong connection string name in <membership> block in web.config. Don't use the Entity Framework Connection string"); return; } // Test Profile API try { UserProfile newProfile = ProfileCommon.Create(Guid.NewGuid().ToString()) as UserProfile; if (newProfile == null) { MarkAsFail(MembershipLabel, "Cannot create new user.", "You might have wrong connection string name in <profile> block. Ensure it's the simple connection string, not the entity framework one. Or you may not have the 'inherits=\"Dropthings.Web.Framework.UserProfile\" attribute in the <profile> block."); return; } newProfile.IsFirstVisit = false; newProfile.Fullname = "Test"; newProfile.Save(); } catch (Exception x) { MarkAsFail(MembershipLabel, x.Message, "Probably wrong connection string name in <profile> block in web.config. Don't use the Entity Framework Connection string"); return; } // Test Role Manager API try { string[] roles = Roles.GetAllRoles(); if (!roles.Contains("Guest")) { MarkAsFail(MembershipLabel, "Guest role does not exist", "You may have an empty database. Dropthings requires some mandetory stuff to be in some tables. There must be a Guest role."); return; } } catch (Exception x) { MarkAsFail(MembershipLabel, x.Message, "Probably wrong connection string name in <roleManager> block in web.config. Don't use the Entity Framework Connection string"); return; } // ALL OK! MarkAsPass(MembershipLabel); } catch (Exception x) { MarkAsFail(MembershipLabel, x.Message, "Membership settings in web.config is incorrect. Please fix"); } }
protected void setMatch(ReuseTech obj) { /* 配對 */ //at = SpringUtil.at(); String sql = "SELECT * FROM ReuseTech "; sql += " WHERE type='2' and ((TechOther like @param1) or (WasteOther like @param2) or (TechName like @param3) or (WasteName like @param4)) "; //IDbParameters parameters = at.CreateDbParameters(); //parameters.Add("param1", OleDbType.VarChar).Value = obj.Techother; //parameters.Add("param2", OleDbType.VarChar).Value = obj.Wasteother; //parameters.Add("param3", OleDbType.VarChar).Value = "%" + obj.Techname + "%"; //parameters.Add("param4", OleDbType.VarChar).Value = "%" + obj.Wastename + "%"; //DataSet ds = new DataSet(); //at.DataSetFillWithParameters(ds, CommandType.Text, sql, parameters); OleDbCommand cmd = new OleDbCommand(sql); cmd.Parameters.Add("param1", OleDbType.VarChar).Value = obj.Techother; cmd.Parameters.Add("param2", OleDbType.VarChar).Value = obj.Wasteother; cmd.Parameters.Add("param3", OleDbType.VarChar).Value = "%" + obj.Techname + "%"; cmd.Parameters.Add("param4", OleDbType.VarChar).Value = "%" + obj.Wastename + "%"; cmd.CommandType = CommandType.Text; DataSet ds = SQLUtil.QueryDS(cmd); if (ds.Tables[0].Rows.Count > 0) { p = Profile.GetProfile(Request.QueryString["Username"].ToString()); ArrayList matchList = new ArrayList(); foreach (DataRow dRow in ds.Tables[0].Rows) { Match match = new Match(); user2 = Membership.GetUser(dRow["UserName"].ToString()); p2 = (ProfileCommon)ProfileCommon.Create(dRow["UserName"].ToString(), true); match.Username1 = Request.QueryString["Username"].ToString(); match.Username2 = dRow["UserName"].ToString(); match.Rid2 = (int)dRow["Id"]; match.Name1 = p.UserProfile.Name; match.Name2 = p2.UserProfile.Name; match.Corp1 = p.UserProfile.Corp; match.Corp2 = p2.UserProfile.Corp; match.Tel1 = p.UserProfile.Tel; match.Tel2 = p2.UserProfile.Tel; match.Wasteitem1 = obj.Wasteother; match.Wasteitem2 = dRow["WasteOther"].ToString(); match.Wastename1 = obj.Wastename; match.Wastename2 = dRow["WasteName"].ToString(); match.Techitem1 = obj.Techother; match.Techitem2 = dRow["TechOther"].ToString(); match.Techname1 = obj.Techname; match.Techname2 = dRow["TechName"].ToString(); match.Reusename1 = obj.Reusename; match.Reusename2 = dRow["ReuseName"].ToString(); match.Matchdate = DateTime.Now; match.Ischecked = "A"; match.Isdeleted = false; match.Isconfirm1 = "A"; match.Isconfirm2 = "A"; match.Isdroped1 = "A"; match.Isdroped2 = "A"; match.Createdate1 = DateTime.Now; match.Createdate2 = (DateTime)dRow["Createdate"]; match.Isapproved1 = true; if (user2.IsApproved) { match.Isapproved2 = true; } else { match.Isapproved2 = false; } match.Techdesc = obj.Techdesc; match.Techadv = obj.Techadv; matchList.Add(match); } //mgr.Save(obj, matchList, null); Save(obj, matchList); } else { //mgr.Save(obj, null, null); EditReuseTech(obj); } }
protected void btnCreatePassword_OnClick(object sender, EventArgs e) { if (tbPassword1.Text.Length < Membership.MinRequiredPasswordLength) { Utils.displayStatus(ref labelStatus, Color.Red, "Administrator passordet må ha minst " + Membership.MinRequiredPasswordLength.ToString() + " tegn"); return; } if (tbPassword1.Text != tbPassword2.Text) { Utils.displayStatus(ref labelStatus, Color.Red, "Passordene er ikke like"); return; } if (!Utils.isValidEmail(tbEmail.Text)) { Utils.displayStatus(ref labelStatus, Color.Red, "Epost adressen er ikke gyldig"); return; } try { MembershipCreateStatus status = new MembershipCreateStatus(); MembershipUser admin = Membership.CreateUser("Administrator", tbPassword1.Text, tbEmail.Text, "Admin question?", "Admin answer", true, out status); if (admin == null) { Utils.displayStatus(ref labelStatus, Color.Red, "Kan ikke opprette administrator bruker"); return; } ProfileCommon prof = (ProfileCommon)ProfileCommon.Create("Administrator", true); prof.Name = "Administrator"; prof.Phone = "00000000"; prof.Email = tbEmail.Text; prof.Title = "Administrator"; prof.Save(); // add roles if missing XPathDocument doc = new XPathDocument(Server.MapPath("App_Data/roles.xml")); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile("/roles/role"); XPathNodeIterator iterator = nav.Select(expr); while (iterator.MoveNext()) { if (!Roles.RoleExists(iterator.Current.Value)) { Roles.CreateRole(iterator.Current.Value); } if (!Roles.IsUserInRole("Administrator", iterator.Current.Value)) { Roles.AddUserToRole("Administrator", iterator.Current.Value); } } // add configuration if missing Database.Interface.open(); Database.Configuration configuration = new Database.Configuration("Default", "", "", "", ""); configuration.insert_with_ID_name(Guid.NewGuid(), "Default"); Utils.displayStatus(ref labelStatus, Color.Green, "Administrator ble opprettet"); btnCreatePassword.Enabled = false; tbPassword1.Enabled = false; tbPassword2.Enabled = false; } catch (Exception ex) { Utils.displayStatus(ref labelStatus, Color.Red, ex.Message); } finally { Database.Interface.close(); } }
protected void setMatch(ReuseTech obj) { /* 配對 */ //at = SpringUtil.at(); String sql = "SELECT * FROM ReuseTech "; sql += " WHERE type='1' and ((TechOther like @param1) or (WasteOther like @param2) or (TechName like @param3) or (WasteName like @param4)) "; //IDbParameters parameters = at.CreateDbParameters(); //parameters.Add("param1", OleDbType.VarChar).Value = obj.Techother; //parameters.Add("param2", OleDbType.VarChar).Value = obj.Wasteother; //parameters.Add("param3", OleDbType.VarChar).Value = "%" + obj.Techname + "%"; //parameters.Add("param4", OleDbType.VarChar).Value = "%" + obj.Wastename + "%"; //DataSet ds = new DataSet(); //at.DataSetFillWithParameters(ds, CommandType.Text, sql, parameters); OleDbCommand cmd = new OleDbCommand(sql); cmd.Parameters.Add("param1", OleDbType.VarChar).Value = obj.Techother; cmd.Parameters.Add("param2", OleDbType.VarChar).Value = obj.Wasteother; cmd.Parameters.Add("param3", OleDbType.VarChar).Value = "%" + obj.Techname + "%"; cmd.Parameters.Add("param4", OleDbType.VarChar).Value = "%" + obj.Wastename + "%"; cmd.CommandType = CommandType.Text; DataSet ds = SQLUtil.QueryDS(cmd); if (ds.Tables[0].Rows.Count > 0) { p = Profile.GetProfile(User.Identity.Name); ArrayList matchList = new ArrayList(); foreach (DataRow dRow in ds.Tables[0].Rows) { Match match = new Match(); user2 = Membership.GetUser(dRow["UserName"].ToString()); p2 = (ProfileCommon)ProfileCommon.Create(dRow["UserName"].ToString(), true); match.Username2 = User.Identity.Name; match.Username1 = dRow["UserName"].ToString(); match.Rid1 = (int)dRow["Id"]; match.Name2 = p.UserProfile.Name; match.Name1 = p2.UserProfile.Name; match.Corp2 = p.UserProfile.Corp; match.Corp1 = p2.UserProfile.Corp; match.Tel2 = p.UserProfile.Tel; match.Tel1 = p2.UserProfile.Tel; match.Wasteitem2 = obj.Wasteother; match.Wasteitem1 = dRow["WasteOther"].ToString(); match.Wastename2 = obj.Wastename; match.Wastename1 = dRow["WasteName"].ToString(); match.Techitem2 = obj.Techother; match.Techitem1 = dRow["TechOther"].ToString(); match.Techname2 = obj.Techname; match.Techname1 = dRow["TechName"].ToString(); match.Reusename2 = obj.Reusename; match.Reusename1 = dRow["ReuseName"].ToString(); match.Matchdate = DateTime.Now; match.Ischecked = "A"; match.Isdeleted = false; match.Isconfirm2 = "A"; match.Isconfirm1 = "A"; match.Isdroped2 = "A"; match.Isdroped1 = "A"; match.Createdate2 = DateTime.Now; match.Createdate1 = (DateTime)dRow["Createdate"]; match.Isapproved2 = true; if (user2.IsApproved) { match.Isapproved1 = true; } else { match.Isapproved1 = false; } match.Techdesc = dRow["TechDesc"].ToString(); match.Techadv = dRow["TechAdv"].ToString(); matchList.Add(match); } Save(obj, matchList); //mgr.Save(obj, matchList, null); /* Mail */ MailMessage msgMail = new MailMessage(); MembershipUser user = Membership.GetUser(User.Identity.Name); string strMsg = ""; string strTo = ""; string strFrom = ""; string strSubject = "資源化技術研發供需資訊平台-新增系統配對結果通知"; strMsg += "<p>請管理者登入「研發合作對象名單」中審核系統自動配對之結果</p>"; MembershipUser mng = Membership.GetUser("isrmng"); strTo = mng.Email; strFrom = mng.Email; msgMail.To = strTo; msgMail.From = strFrom; msgMail.Subject = strSubject; msgMail.BodyFormat = MailFormat.Html; msgMail.Body = strMsg; msgMail.Cc = "*****@*****.**"; new util().SendMail(strFrom, strTo, strSubject, strMsg, "*****@*****.**"); //SmtpMail.Send(msgMail); /* Mail End */ } else { EditReuseTech(obj); //mgr.Save(obj, null, null); } }