CreateUser() public method

public CreateUser ( string userName, string password, string email ) : MembershipCreateStatus,
userName string
password string
email string
return MembershipCreateStatus,
 public ActionResult Index(int dinnerCount = 100)
 {
     const string name = "Nerd";
     var membershipService = new AccountMembershipService();
     if(membershipService.ValidateUser(name, "password") == false) {
         membershipService.CreateUser(name, "password", "*****@*****.**");
     }
     var repo = new DinnerRepository();
     foreach(var d in repo.All) {
         repo.Delete(d.DinnerID);
     }
     for (var i = 0; i < dinnerCount; i++) {
         var dinner = new Dinner {Title = "Nerd-Out",
                                  Description = "Nerding out with the nerds",
                                  EventDate = DateTime.Now.Add(new TimeSpan(30, 0, 0, 0)),
                                  ContactPhone = "403-999-9999",
                                  Address = "Calgary, AB",
                                  Country = "Canada",
                                  HostedById = name,
                                  HostedBy = name};
         var rsvp = new RSVP {AttendeeNameId = name, AttendeeName = name};
         dinner.RSVPs = new List<RSVP> {rsvp};
         repo.InsertOrUpdate(dinner);
     }
     try {
         repo.Save();
     }
     catch(DbEntityValidationException e) {
         var error = e.EntityValidationErrors.First().ValidationErrors.First();
         return new ContentResult {Content = string.Format("{0}: {1}", error.PropertyName, error.ErrorMessage)};
     }
     return new ContentResult{Content = "Success"};
 }
Exemplo n.º 2
0
        public ActionResult Staff(itmmAdminStaff model, string type)
        {
            if (ModelState.IsValid)
            {
                AccountMembershipService MembershipService = new AccountMembershipService();
                MembershipCreateStatus   createStatus      = MembershipService.CreateUser(model.uname, model.password, model.eadd);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRole(model.uname, "Staff");

                    Laboratory_Staff a = new Laboratory_Staff();
                    a.FirstName     = model.fname;
                    a.LastName      = model.lname;
                    a.IdNumber      = model.cnum;
                    a.CourseAndYear = model.course;
                    a.EmailAddress  = model.eadd;
                    a.Type          = type;
                    a.UserName      = model.uname;
                    //for LabId
                    var c = (from y in con.Laboratories
                             where y.UserName == User.Identity.Name
                             select y.LaboratoryId).FirstOrDefault();
                    a.LaboratoryId = c;
                    con.AddToLaboratory_Staff(a);
                    con.SaveChanges();

                    return(RedirectToAction("Staff", "Head"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            return(View(model));
        }
Exemplo n.º 3
0
        public static void AddDefaultAccount()
        {
            var svc = new AccountMembershipService();

            if (svc.ValidateUser("zys", "112233445566") == false)
            {
                svc.CreateUser("zys", "112233445566", "*****@*****.**");
            }
        }
Exemplo n.º 4
0
        public ActionResult Head(itmmAdminHead model, int section)
        {
            var l = from y in con.Laboratories
                    orderby y.LaboratoryName ascending
                    select y;

            ViewBag.LabList = l;

            var b = from y in con.Laboratory_Head
                    select y;

            ViewBag.HeadList = b;

            if (ModelState.IsValid)
            {
                AccountMembershipService MembershipService = new AccountMembershipService();
                MembershipCreateStatus   createStatus      = MembershipService.CreateUser(model.uname, model.password, model.eadd);
                if (createStatus == MembershipCreateStatus.Success)
                {
                    Roles.AddUserToRole(model.uname, "Head");
                    Laboratory_Head a = new Laboratory_Head();
                    a.FirstName    = model.fname;
                    a.LastName     = model.lname;
                    a.UserName     = model.uname;
                    a.ContactNum   = model.cnum;
                    a.EmailAdd     = model.eadd;
                    a.LaboratoryId = section;

                    var x = (from y in con.Laboratories
                             where y.LaboratoryId == section
                             select y).FirstOrDefault();

                    x.UserName = model.uname;

                    con.AddToLaboratory_Head(a);

                    con.SaveChanges();


                    return(RedirectToAction("Head", "Admin"));
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }
            return(View(model));
        }
        private static void RequiredData(string installDirPath, string adminUser, string adminPass)
        {
            MembershipCreateStatus   createStatus;
            AccountMembershipService membershipService = new AccountMembershipService();
            AccountRoleService       roleService       = new AccountRoleService();

            Common.Models.Account.Users user = Data.Account.Users.Get("Administrator");
            if (user == null)
            {
                createStatus = membershipService.CreateUser(adminUser, adminPass,
                                                            Common.Settings.Manager.Instance.System.AdminEmail, true);
            }

            if (!roleService.RoleExists("Login"))
            {
                roleService.CreateRole("Login");
            }

            if (!roleService.RoleExists("Admin"))
            {
                roleService.CreateRole("Admin");
            }

            if (!roleService.RoleExists("User"))
            {
                roleService.CreateRole("User");
            }

            if (!roleService.RoleExists("Client"))
            {
                roleService.CreateRole("Client");
            }

            if (!roleService.IsUserInRole(adminUser, "Login"))
            {
                roleService.AddUserToRole(adminUser, "Login");
            }

            if (!roleService.IsUserInRole(adminUser, "Admin"))
            {
                roleService.AddUserToRole(adminUser, "Admin");
            }

            if (!roleService.IsUserInRole(adminUser, "User"))
            {
                roleService.AddUserToRole(adminUser, "User");
            }
        }
        private static void RequiredData(string installDirPath, string adminUser, string adminPass)
        {
            MembershipCreateStatus createStatus;
            AccountMembershipService membershipService = new AccountMembershipService();
            AccountRoleService roleService = new AccountRoleService();

            Common.Models.Account.Users user = Data.Account.Users.Get("Administrator");
            if (user == null)
            {
                createStatus = membershipService.CreateUser(adminUser, adminPass, 
                    Common.Settings.Manager.Instance.System.AdminEmail, true);
            }

            if (!roleService.RoleExists("Login"))
            {
                roleService.CreateRole("Login");
            }

            if (!roleService.RoleExists("Admin"))
            {
                roleService.CreateRole("Admin");
            }

            if (!roleService.RoleExists("User"))
            {
                roleService.CreateRole("User");
            }

            if (!roleService.RoleExists("Client"))
            {
                roleService.CreateRole("Client");
            }

            if (!roleService.IsUserInRole(adminUser, "Login"))
            {
                roleService.AddUserToRole(adminUser, "Login");
            }

            if (!roleService.IsUserInRole(adminUser, "Admin"))
            {
                roleService.AddUserToRole(adminUser, "Admin");
            }

            if (!roleService.IsUserInRole(adminUser, "User"))
            {
                roleService.AddUserToRole(adminUser, "User");
            }
        }
        public ActionResult PatientSignUp(PatientRegistrationModel model)
        {
            ReadOnlyCollection <TimeZoneInfo> tz    = TimeZoneInfo.GetSystemTimeZones();
            List <SelectListItem>             items = new List <SelectListItem>();

            //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(timezone);

            //double offSetHours = tzi.BaseUtcOffset.TotalHours + ((tzi.IsDaylightSavingTime(DateTime.Now)) ? 1 : 0);
            foreach (TimeZoneInfo tzi in tz)
            {
                items.Add(new SelectListItem {
                    Text = tzi.DisplayName, Value = tzi.Id
                });
            }
            ViewBag.CurrenttimeZone = items;
            try
            {
                //if (this.IsCaptchaValid("Captcha is not valid"))
                // RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

                //if (String.IsNullOrEmpty(recaptchaHelper.Response))
                //{
                //    ModelState.AddModelError("", "Error :Captcha value cannot be empty.");
                //    return View(model);
                //}

                // RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

                //if (recaptchaResult != RecaptchaVerificationResult.Success)
                //{
                //    ModelState.AddModelError("", "Error :Incorrect captcha value.");
                //    return View(model);
                //}
                //else
                //{
                if (model.USERSTATE != null || model.COUNTRY != null)
                {
                    if (ModelState.IsValid)
                    {
                        if (model.AGREETERMS)
                        {
                            USERSINFORMATION       user         = uw.Context.UsersInformations.SingleOrDefault(f => f.UserName == model.UserName);
                            MembershipCreateStatus createStatus = MembershipCreateStatus.UserRejected;
                            if (user == null)
                            {
                                createStatus = account.CreateUser(model.UserName, model.PASSWORD, model.UserName);
                            }

                            if (createStatus == MembershipCreateStatus.Success)
                            {
                                using (var repo = new PatientInformationRepository(uw))
                                {
                                    user = uw.Context.UsersInformations.SingleOrDefault(f => f.UserName == model.UserName);
                                    USERPASSWORD  userpwd = new USERPASSWORD();
                                    StringBuilder bodyMsg = new StringBuilder();
                                    user.PASSWORDHASH           = user.PASSWORDHASH;
                                    user.PASSWORDSALT           = user.PASSWORDSALT;
                                    user.DateLastActivity       = DateTime.UtcNow;
                                    user.DateLastLogin          = DateTime.UtcNow;
                                    user.DateLastPasswordChange = DateTime.UtcNow;
                                    user.IsApproved             = false;
                                    user.IsfirstLogin           = "******";
                                    user.FIRSTNAME = model.FIRSTNAME;
                                    user.LASTNAME  = model.LASTNAME;
                                    user.GENDER    = model.GENDER;
                                    //model.DOB = new DateTime(Convert.ToInt32(model.DOBYEAR), Convert.ToInt32(model.DOBMonth), Convert.ToInt32(model.DOBDAY));
                                    //user.DOB = model.DOB;
                                    user.USERTYPE = "P";
                                    //user.STREETADDRESS = model.USERSTREETADDRESS1;
                                    //user.CITY = model.CITY;
                                    user.COUNTRY = model.COUNTRY;
                                    if (model.COUNTRY != null && model.COUNTRY == "United States")
                                    {
                                        user.USERSTATE = model.USERSTATE;
                                    }
                                    //user.ZIPCODE = model.ZIPCODE;
                                    user.UserName        = model.UserName;
                                    user.Email           = model.UserName;
                                    user.SECURITYQESTID1 = model.SECURITYQESTID1;
                                    user.ANSWER1         = model.ANSWER1;
                                    //user.SECURITYQESTID2 = model.SECURITYQESTID2;
                                    //user.ANSWER2 = model.ANSWER2;
                                    user.AGREETERMS        = true;
                                    user.USERPHOTOFILEPATH = "/Images/profile_doctor.jpg";
                                    user.VERIFICATIONCODE  = GenerateRandom.genereteRandomNumber();
                                    user.CREATEDBY         = User.Identity.Name;
                                    user.MODIFIEDBY        = User.Identity.Name;
                                    user.DateCreated       = DateTime.UtcNow;
                                    user.MODIFIEDON        = DateTime.UtcNow;
                                    user.REGISTEREDON      = DateTime.UtcNow;
                                    //user.CurrenttimeZone = model.CurrenttimeZone;
                                    //user.Salutation = model.Salutation;
                                    user.HITCOUNT = "0";
                                    user.State    = State.Modified;

                                    PATIENTINFORMATION patientInformation = new PATIENTINFORMATION();
                                    patientInformation.MODIFIEDBY  = User.Identity.Name;
                                    patientInformation.DateCreated = DateTime.UtcNow;
                                    patientInformation.MODIFIEDON  = DateTime.UtcNow;
                                    patientInformation.CREATEDBY   = User.Identity.Name;
                                    patientInformation.POVEMAIL    = user.UserName;
                                    patientInformation.PATIENTTYPE = "P";
                                    patientInformation.State       = DOCVIDEO.ObjectState.State.Added;
                                    patientInformation.UserName    = user.UserName;

                                    user.PatientInformations.Add(patientInformation);

                                    userpwd.CREATEDBY    = User.Identity.Name;
                                    userpwd.MODIFIEDON   = DateTime.UtcNow;
                                    userpwd.DateCreated  = DateTime.UtcNow;
                                    userpwd.MODIFIEDBY   = User.Identity.Name;
                                    userpwd.State        = State.Added;
                                    userpwd.UserName     = model.UserName;
                                    userpwd.EXPIRYDATE   = DateTime.UtcNow.AddMonths(1);
                                    userpwd.PASSWORDHASH = user.PASSWORDHASH;
                                    userpwd.PASSWORDSALT = user.PASSWORDSALT;
                                    userpwd.STATUS       = "A";
                                    user.UserPasswords.Add(userpwd);

                                    repo.InsertOrUpdate(user);
                                    uw.Save();
                                    string comment = "Patient SignUp.";
                                    string data    = string.Format("<Data><Info><![CDATA[{0}]]></Info></Data>", comment);
                                    //DOCVIDEO.DAL.Event.EventPublisher.PublishEvent((int)DocVideoEvents.PatientSignUp, 0, 0, model.UserName, data);

                                    /*
                                     *
                                     * bodyMsg.Append("<div style='width: 750px; background-color: #fff; color: #4d4d4d; border: 1px solid #999; font-size: 14px; font-family: serif; letter-spacing: 0.02em;'>");
                                     * bodyMsg.Append("<div style='height: 50px; border-bottom: 1px solid #aaa; background: #D3D0D0; padding: 8px;'>");
                                     * bodyMsg.Append("<div>");
                                     * bodyMsg.Append("<img src='" + System.Configuration.ConfigurationManager.AppSettings["server_url"] + "/content/images/logo.png' title='doccare_logo' alt='docare logo' /></div>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<div style='padding: 10px;'>");
                                     * bodyMsg.Append("<div style='text-align: right;'>Date:" + String.Format("{0:dddd, MMMM d, yyyy HH:mm:ss tt}", DateTime.Now) + "</div>");
                                     * bodyMsg.Append("<h2 style='color: #1072B5; font-style: italic;'>Dear," + model.FIRSTNAME + " " + model.LASTNAME + "</h2>");
                                     * bodyMsg.Append("<div style='float: left; width: 490px;'>");
                                     * bodyMsg.Append("<div>Thank you for signing up with docare. <br/>");
                                     * bodyMsg.Append("docare online is an online care system that allows patients to connect with doctors immediately, whenever and wherever.");
                                     * bodyMsg.Append("Please  <a href='" + System.Configuration.ConfigurationManager.AppSettings["server_url"] + "Account/LogOn?id=" + user.VERIFICATIONCODE + " 'title='Click'  style='color: #1072B5;'>Click here  </a>   to login to your docare account!");
                                     * bodyMsg.Append("Account.");
                                     * bodyMsg.Append(" </p>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<div style='color: #1072B5; margin: 10px 0px -10px 0px;'><strong>Benefits of signing up</strong></div>");
                                     * bodyMsg.Append("<div style='font-style: italic; font-weight: bold; line-height: 20px;'>");
                                     * bodyMsg.Append("<ul>");
                                     * bodyMsg.Append("<li>Access to doctors’ profiles and quality e-medicine</li>");
                                     * bodyMsg.Append("<li>No travel time</li>");
                                     * bodyMsg.Append("<li>Minimal wait time </li>");
                                     * bodyMsg.Append("<li>No insurance paperwork</li>");
                                     * bodyMsg.Append("<li>Electronic scheduling</li>");
                                     * bodyMsg.Append("<li>Avoid waiting rooms </li>");
                                     * bodyMsg.Append("<li>Eliminate time off from work. </li>");
                                     * bodyMsg.Append("</ul>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<div style='color: #1072B5; text-align: center; font-size: 19px; font-style: italic;'>");
                                     * bodyMsg.Append("<strong>See your Doctors, anytime, anywhere!</strong>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<p>");
                                     * bodyMsg.Append(" If you have questions about docare online, please email us at");
                                     * bodyMsg.Append("<a href='mailto:[email protected].' style='color: #1072B5;'>  [email protected].</a> For FAQ, please visit <a href=' www.PROFESSORSONLINE.com/faq' title='PROFESSORSONLINE' style='color: #1072B5;'> www.PROFESSORSONLINE.com/faq.</a>");
                                     * bodyMsg.Append("</p>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<div style='float: right; margin-left: 10px; width: 230px;'>");
                                     * bodyMsg.Append("<img src='" + System.Configuration.ConfigurationManager.AppSettings["server_url"] + "/content/images/amy_inner.png' alt='amy_image' />");
                                     * bodyMsg.Append("<div style='color: #1072B5; text-align: center; font-size: 19px; font-style: italic;'>docare online helps doctors and patients connect securely anytime, anywhere!</div>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<div style='clear: both;'></div>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("<div style='font-size: 12px; background: #D3D0D0; padding: 10px; clear: both; margin-top: 10px;'>");
                                     * bodyMsg.Append("<strong>Disclaimer:</strong> This message is intended for the use of the person or entity to which it is addressed and may contain information that is privileged and confidential, the disclosure of which is governed by applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this information is STRICTLY PROHIBITED. If you have received this message by error, please notify us immediately and destroy the related message. You, the recipient, are obligated to maintain it in a safe, secure and confidential manner. Re-disclosure without appropriate member authorization or as permitted by law is prohibited. Unauthorized re-disclosure or failure to maintain confidentiality <strong>could subject you to penalties described in Federal and State law.</strong>");
                                     * bodyMsg.Append("</div>");
                                     * bodyMsg.Append("</div>");
                                     *
                                     * //Mail to pateint
                                     * DOCVIDEO.Utility.MailUtility.SendEmail("*****@*****.**", model.UserName, "", "", "Welcome to docare online", bodyMsg.ToString(), false, "", 0);
                                     */
                                    return(RedirectToAction("RegistrationSuccess", "Account"));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("", "Error :This user is already registered.");
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Error : Please accept the terms of service.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Error: Some data are not valid.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Error: Please enter User State or Country.");
                }

                //}
            }
            catch (Exception ex)
            {
                throw new CustomException("Exception:- Project: {0} \n Error Message: {1} ", ex.InnerException, new Object[] { ex.Source, ex.Message });
            }
            return(View(model));
        }