Example #1
0
        public async Task <ActionResult <JobSeekerUser> > PostJobSeeker(JobSeekerUser jobSeeker)
        {
            _context.jobSeekerUsers.Add(jobSeeker);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetJobSeeker", new { id = jobSeeker.Id }, jobSeeker));
        }
Example #2
0
        public async Task <IActionResult> PutJobSeeker(int id, JobSeekerUser jobSeeker)
        {
            if (id != jobSeeker.Id)
            {
                return(BadRequest());
            }

            _context.Entry(jobSeeker).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JobSeekerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            JobSeekerUser jobSeekerUser = db.JobSeekerUsers.Find(id);

            db.JobSeekerUsers.Remove(jobSeekerUser);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "JobSeekerUserID,JobSeekerName,JobSeekerPhoneNumber,JobSeekerDoB,LastLoginDate,JobSeekerExpertise,CVFiles")] JobSeekerUser jobSeekerUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jobSeekerUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(jobSeekerUser));
 }
        public ActionResult Create([Bind(Include = "JobSeekerUserID,JobSeekerName,JobSeekerPhoneNumber,JobSeekerDoB,LastLoginDate,JobSeekerExpertise,CVFiles")] JobSeekerUser jobSeekerUser)
        {
            if (ModelState.IsValid)
            {
                db.JobSeekerUsers.Add(jobSeekerUser);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(jobSeekerUser));
        }
        // GET: JobSeekerUsers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            JobSeekerUser jobSeekerUser = db.JobSeekerUsers.Find(id);

            if (jobSeekerUser == null)
            {
                return(HttpNotFound());
            }
            return(View(jobSeekerUser));
        }
Example #7
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var jobSeeker = new JobSeeker {
                    Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };
                // context.JobSeekers.Add(jobSeeker);
                // await context.SaveChangesAsync();
                var user = new JobSeekerUser {
                    Email = model.Email, JobSeeker = jobSeeker, UserName = model.Email
                };

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

                if (result.Succeeded)
                {
                    inisraRoleManager = new RoleManager <IdentityRole>
                                            (new RoleStore <IdentityRole>(context));
                    var roleResult = UserManager.AddToRole(user.Id, "JobSeeker");

                    if (roleResult.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(roleResult);
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    throw new ApplicationException("Error loading external login information during confirmation.");
                }
                var Checkemail = await _userManager.FindByEmailAsync(model.Email);

                if (Checkemail != null)
                {
                    var result1 = await _userManager.AddLoginAsync(Checkemail, info);

                    if (!result1.Succeeded)
                    {
                        throw new ApplicationException($"Unexpected error occurred adding external login for user with ID '{Checkemail.Id}'.");
                    }
                    else
                    {
                        await _signInManager.SignInAsync(Checkemail, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(RedirectToLocal(returnUrl));
                    }
                }
                else
                {
                    //var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                    var user = new JobSeekerUser
                    {
                        FullName           = model.FullName,
                        UserName           = model.Email,
                        Email              = model.Email,
                        DateCreated        = DateTime.Now,
                        DateUpdated        = DateTime.Now,
                        LastLoginDate      = DateTime.Now,
                        PasswordChangeDate = DateTime.Now,
                        EmailConfirmed     = true,
                        Birthday           = Convert.ToDateTime("01/01/2000"),
                    };
                    var result = await _userManager.CreateAsync(user);

                    if (result.Succeeded)
                    {
                        result = await _userManager.AddLoginAsync(user, info);

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

                            _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                            return(RedirectToLocal(returnUrl));
                        }
                    }
                    AddErrors(result);
                }
            }

            ViewData["ReturnUrl"] = returnUrl;
            return(View(nameof(ExternalLogin), model));
        }
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                @ViewData["Message"] = "Model valid";
                var user = new JobSeekerUser
                {
                    FullName           = model.FullName,
                    UserName           = "******" + model.Email,
                    Email              = "IJobSeekerUserI" + model.Email,
                    NormalizedUserName = "******" + model.Email,
                    NormalizedEmail    = "IJobSeekerUserI" + model.Email,
                    PhoneNumber        = model.PhoneNumber,
                    DateCreated        = DateTime.Now,
                    DateUpdated        = DateTime.Now,
                    LastLoginDate      = DateTime.Now,
                    PasswordChangeDate = DateTime.Now,
                    Birthday           = Convert.ToDateTime("01/01/2000")
                                         //SecurityStamp = Guid.NewGuid().ToString()
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _userManager.AddToRoleAsync(user, "Seeker");

                    _logger.LogInformation("User created a new account with password.");

                    // Lấy token xác nhận tài khoản
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    // Gọi UrlHelperExtensions.cs lấy được chuỗi dẫn đến AccountController.ConfirmEmail
                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);

                    // Gửi mail chuỗi callbackUrl gọi hàm AccountController.ConfirmEmail
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    //await _signInManager.SignInAsync(user, isPersistent: false); //isPersistent
                    _logger.LogInformation("User created a new account with password.");
                    //return RedirectToLocal(returnUrl);
                    ViewData["EmailConfirm"] = model.Email;
                    return(View("SendingEmailConfirm", new SendingEmailConfirmViewModel
                    {
                        Email = model.Email,
                    }));
                }
                AddErrors(result);
            }
            else
            {
                @ViewData["Message"] = "Invalid!!!";
            }
            //Định nghĩa isPersistent
            //Persistent cookies will be saved as files in the browser folders until they either expire or manually deleted.
            //This will cause the cookie to persist even if you close the browser.
            //If IsPersistent is set to false, the browser will acquire session cookie which gets cleared when the browser is closed

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