public async Task <ActionResult> Register(RegisterViewModel model)
        {
            //HttpPostedFileBase idFile ;
            if (ModelState.IsValid)
            {
                var User = new member {
                    UserName = model.username, Email = model.Email, firstName = model.FirstName, lastName = model.lastName, DTYPE = "Member", role = "Member", image_link = "~/Content/img/avatar.jpg"
                };
                var username   = model.username;
                var image_link = model.image_link;
                ViewBag.image_link = image_link;

                var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore <IdentityRole>(new tagContext()));
                if (!roleManager.RoleExists("Member"))
                {
                    var Role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    Role.Name = "Member";
                    roleManager.Create(Role);
                }
                tagContext ctx    = new tagContext();
                var        result = await UserManager.CreateAsync(User, model.Password);

                var role = UserManager.AddToRole(User.Id, "Member");
                var 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 this link: <a href=\""
                                                 + callbackUrl + "\">link</a>");

                ctx.SaveChanges();


                return(View("DisplayEmail"));
            }



            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create(AddCrewViewModel model, HttpPostedFileBase idFile)
        {
            if (ModelState.IsValid)
            {
                tagContext ctx  = new tagContext();
                string     link = Guid.NewGuid().ToString() +
                                  System.IO.Path.GetExtension(idFile.FileName);
                var uploadUrl = Server.MapPath("~/Content/img");
                idFile.SaveAs(Path.Combine(uploadUrl, link));
                model.image_link = "img\\" + link;
                var User = new User()
                {
                    UserName = model.username, Email = model.Email, firstName = model.FirstName, lastName = model.lastName, DTYPE = "Event_Organizer", role = "Event_Organizer", image_link = model.image_link
                };
                var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore <IdentityRole>(new tagContext()));
                if (!roleManager.RoleExists("Event_Organizer"))
                {
                    var Role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                    Role.Name = "Event_Organizer";
                    roleManager.Create(Role);
                }
                var result = await UserManager.CreateAsync(User, model.Password);

                var id = User.Id;
                System.Console.WriteLine(id);
                var role = UserManager.AddToRole(id, "Event_Organizer");
                var 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 this link: <a href=\""
                                                 + callbackUrl + "\">link</a>");

                ctx.SaveChanges();
                return(RedirectToAction("Index_Event_Organizer"));
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 3
0
        public async Task <IdentityResult> RegisterUser(RegisterViewModel model)
        {
            var User = new member {
                UserName = model.username, Email = model.Email, firstName = model.FirstName, lastName = model.lastName, DTYPE = "Member", role = "Member", image_link = model.image_link
            };
            var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore <IdentityRole>(new tagContext()));

            if (!roleManager.RoleExists("Member"))
            {
                var Role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                Role.Name = "Member";
                roleManager.Create(Role);
            }
            tagContext ctx    = new tagContext();
            var        result = await _userManager.CreateAsync(User, model.Password);

            var role = _userManager.AddToRole(User.Id, "Member");

            //var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("G-Nation");
            //_userManager.UserTokenProvider = new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<User>(provider.Create("EmailConfirmation"));
            //var token = await _userManager.GenerateEmailConfirmationTokenAsync(User.Id);
            //await _userManager.UserTokenProvider.GenerateAsync("Confirmation", _userManager, User);
            //await _userManager.UserTokenProvider.ValidateAsync("Confirmation", token, _userManager, User);

            //var 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 this link: <a href=\""
            //                                   + callbackUrl + "\">link</a>");

            ctx.SaveChanges();


            return(result);
        }
Exemplo n.º 4
0
        public async Task <IdentityResult> RegisterExternalUser(RegisterViewModel model)
        {
            var User = new member {
                UserName = model.username, Email = model.Email, firstName = model.FirstName, lastName = model.lastName, DTYPE = "Member", role = "Member", image_link = model.image_link
            };
            var roleManager = new RoleManager <Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore <IdentityRole>(new tagContext()));

            if (!roleManager.RoleExists("Member"))
            {
                var Role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                Role.Name = "Member";
                roleManager.Create(Role);
            }
            tagContext ctx    = new tagContext();
            var        result = await _userManager.CreateAsync(User);

            var role = _userManager.AddToRole(User.Id, "Member");


            ctx.SaveChanges();


            return(result);
        }
Exemplo n.º 5
0
 public void Commit()
 {
     dataContext.SaveChanges();
 }