Esempio n. 1
0
        public async Task <ActionResult> Register(AccountViewModels.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName       = model.Email,
                    Email          = model.Email,
                    DrivingLicense = model.DrivingLicense,
                    Phone          = model.Phone
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 2
0
        public async Task <ActionResult> Register(AccountViewModels.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                IdentityResult result;

                // Switch on Selected Account type
                switch (model.AccountType)
                {
                // Volunteer Account type selected:
                case Domain.EAccountType.Patient:
                {
                    // create new volunteer and map form values to the instance
                    Patient v = new Patient {
                        UserName = model.Email, Email = model.Email, address = model.address, firstName = model.firstName, lastName = model.lastName
                    };
                    result = await UserManager.CreateAsync(v, model.Password);

                    // Add volunteer role to the new User
                    if (result.Succeeded)
                    {
                        // UserManager.AddToRole(v.Id, EAccountType.Patient.ToString());
                        await SignInManager.SignInAsync(v, isPersistent : false, rememberBrowser : false);

                        // Email confirmation here

                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);
                }
                break;

                // Ngo Account type selected:
                case EAccountType.Doctor:
                {
                    // create new Ngo and map form values to the instance
                    Doctor ngo = new Doctor {
                        UserName = model.Email, Email = model.Email, address = model.address, firstName = model.firstName, lastName = model.lastName
                    };
                    result = await UserManager.CreateAsync(ngo, model.Password);

                    // Add Ngo role to the new User
                    if (result.Succeeded)
                    {
                        //     UserManager.AddToRole(ngo.Id, EAccountType.Doctor.ToString());
                        await SignInManager.SignInAsync(ngo, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("Index", "Home"));
                    }
                    // AddErrors(result);
                }
                break;
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 //[ValidateAntiForgeryToken]
 public async Task <IHttpActionResult> Register([FromBody] AccountViewModels.RegisterViewModel model, string returnUrl = null)
 {
     //ViewData["ReturnUrl"] = returnUrl;
     try
     {
         using (Entities db = new Entities())
         {
             AspNetUser createUser = new AspNetUser();
             createUser.UserName       = model.Email;
             createUser.Email          = model.Email;
             createUser.FirstName      = model.FirstName;
             createUser.LastName       = model.LastName;
             createUser.City           = model.City;
             createUser.Zip            = model.Zip;
             createUser.State          = model.State;
             createUser.CreatedDate    = DateTime.Now;
             createUser.IsDisable      = false;
             createUser.EmailConfirmed = false;
             using (MD5 md5Hash = MD5.Create())
             {
                 string passwordhash = PasswordHashHelper.GetMd5Hash(md5Hash, model.Password);
                 createUser.PasswordHash = passwordhash;
             }
             createUser.PhoneNumber          = null;
             createUser.PhoneNumberConfirmed = false;
             createUser.TwoFactorEnabled     = false;
             createUser.LockoutEndDateUtc    = null;
             createUser.LockoutEnabled       = true;
             createUser.AccessFailedCount    = 0;
             db.AspNetUsers.Add(createUser);
             db.SaveChanges();
             var firstOrDefaultUser = db.AspNetUsers.FirstOrDefault(
                 usr =>
                 usr.Email == model.Email && usr.FirstName == model.FirstName &&
                 usr.LastName == model.LastName);
             if (firstOrDefaultUser != null)
             {
                 //int roleId =firstOrDefaultUser.Id;
                 var userRoleId = model.EmployeeRole == "Manager" ? 1 : 2;
                 //db.addUserRole(firstOrDefaultUser.Id, userRoleId);
                 //db.SaveChanges();
             }
             return(Ok(true));
         }
     }
     catch (Exception ex)
     {
         return(Ok(false));
     }
 }
Esempio n. 4
0
        public ActionResult Register(AccountViewModels.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                IdentityResult result = new IdentityResult();

                _userService.RegisterUser(model.Name, model.Email, model.Password, model.AccountType, ref result);

                AddErrors(result);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 5
0
        public async Task <ActionResult> RegisterStudent(AccountViewModels.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var client = new HttpClient())
                {
                    var response = await client.PostAsJsonAsync(BaseUrl + "Api/Account/Register/Student", model);


                    if (response.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Login"));
                    }

                    ModelState.AddModelError("", "Error while registering user = "******"RegisterStudent", model));
                }
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("RegisterStudent", model));
        }
Esempio n. 6
0
        public IActionResult Register(AccountViewModels.RegisterViewModel register)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            if (_userRepository.ISExistByEmail(register.Email.ToLower()))
            {
                ModelState.AddModelError("Email", "ایمیل وارد شده قبلا ثبت نام کرده است");
                return(View());
            }

            Users user = new Users()
            {
                Email    = register.Email.ToLower(),
                Password = register.Password,
                IsAdmin  = false
            };

            _userRepository.AddUser(user);

            return(View("SuccessRegister", register));
        }
        public async Task <ActionResult> Register(AccountViewModels.RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                IdentityResult result;

                // Switch on Selected Account type
                switch (model.AccountType)
                {
                // Volunteer Account type selected:
                case Domain.EAccountType.Patient:
                {
                    //   String s=User.Identity.GetUserName();

                    // create new volunteer and map form values to the instance
                    Patient v = new Patient {
                        UserName = model.Email, Email = model.Email, FirstName = model.FirstName
                    };
                    v.EmailConfirmed = true;
                    v.SecurityStamp  = null;
                    Course c = new Course();
                    v.course = c;
                    SC.Add(c);
                    SC.Commit();
                    result = await UserManager.CreateAsync(v, model.Password);

                    //  c.steps
                    //  SC.Add(c);
                    //     ctx.Courses.Add(c);
                    //      ctx.SaveChanges();

                    // ctx.Users.Add(u);

                    //   ctx.SaveChanges();

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(v, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);
                }
                break;

                // Ngo Account type selected:
                case EAccountType.Doctor:
                {
                    // create new Ngo and map form values to the instance
                    Doctor ngo = new Doctor {
                        UserName = model.Email, Email = model.Email, FirstName = model.FirstName
                    };
                    ngo.EmailConfirmed = true;
                    ngo.SecurityStamp  = null;
                    result             = await UserManager.CreateAsync(ngo, model.Password);

                    // Add Ngo role to the new User
                    if (result.Succeeded)
                    {
                        //     UserManager.AddToRole(ngo.Id, EAccountType.Doctor.ToString());
                        await SignInManager.SignInAsync(ngo, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);
                }
                break;
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Register(AccountViewModels.RegisterViewModel model, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                IdentityResult result;
                model.ImageName = Image.FileName;


                // Switch on Selected Account type
                switch (model.AccountType)
                {
                // Volunteer Account type selected:
                case EAccountType.Patient:
                {
                    // create new volunteer and map form values to the instance

                    Patient v = new Patient {
                        UserName    = (model.UserName),
                        Email       = model.Email,
                        Address     = model.Address,
                        FirstName   = model.FirstName,
                        LastName    = model.LastName,
                        BirthDate   = model.BirthDate,
                        ImageName   = model.ImageName,
                        PhoneNumber = model.PhoneNumber,
                        Gender      = model.Gender,
                    };

                    //v.Roles.Add();
                    if (v.ImageName == null)
                    {
                        v.ImageName = "default-user-image.png";
                    }

                    var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName);
                    Image.SaveAs(path);


                    result = await UserManager.CreateAsync(v, model.Password);

                    // Add volunteer role to the new User
                    if (result.Succeeded)
                    {
                        // UserManager.AddToRole(v.Id, EAccountType.Patient.ToString());
                        await SignInManager.SignInAsync(v, isPersistent : false, rememberBrowser : false);

                        // Email confirmation here

                        UserCoUserName = null;
                        return(RedirectToAction("Index", "Home"));
                    }
                    AddErrors(result);
                }
                break;

                // Ngo Account type selected:
                case EAccountType.Doctor:
                {
                    // create new Ngo and map form values to the instance

                    Doctor ngo = new Doctor {
                        UserName    = model.UserName,
                        Email       = model.Email,
                        Address     = model.Address,
                        FirstName   = model.FirstName,
                        LastName    = model.LastName,
                        BirthDate   = model.BirthDate,
                        ImageName   = model.ImageName,
                        PhoneNumber = model.PhoneNumber,
                        Gender      = model.Gender,
                        Speciality  = model.Speciality
                    };
                    if (ngo.ImageName == null)
                    {
                        ngo.ImageName = "default-user-image.png";
                    }

                    var path = Path.Combine(Server.MapPath("~/Content/Upload/"), Image.FileName);
                    Image.SaveAs(path);

                    result = await UserManager.CreateAsync(ngo, model.Password);


                    // Add Ngo role to the new User
                    if (result.Succeeded)
                    {
                        //     UserManager.AddToRole(ngo.Id, EAccountType.Doctor.ToString());
                        await SignInManager.SignInAsync(ngo, isPersistent : false, rememberBrowser : false);

                        UserCoUserName = ngo.UserName;
                        return(RedirectToAction("Index", "Home"));
                    }
                    // AddErrors(result);
                }
                break;
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }