public IActionResult JobseekerRegistration(JobSeekerViewModel user) { var message = "User registered successfully, please login to proceed."; try { if (ModelState.IsValid) { var basePath = string.Format("{0}://{1}{2}", Request.Scheme, URLprotocol, Request.Host); var link = basePath + "/Auth/JobSeekerLogin"; user.RoleId = 2;//For Student authHandler.RegisterUser(user); var eModel = new EmailViewModel { Subject = "Welcome to SRLMS.com", Body = "<b>Dear " + user.FirstName + "</b>," + "<br/><br/>Congratulations! You have successfully registered with" + " SRLMS.com<br/>" + "<br/>Please note that your username and password are both case sensitive.<br/><br/>Your login details are below:<br/><br/>" + "User Name: " + user.Email + "<br>Password: "******"<br/><br/>You can update your contact and registration details at any time by logging on to SRLMS.com" + "<br/><br/>Wish you all the best!<br/><a href=" + link + "> SrLMS.com</a> Team", To = new string[] { user.Email }, From = config["EmailCredential:Fromemail"], IsHtml = true, MailType = (int)MailType.ForgotPassword }; TempData["successMsg"] = "Registration Successful Please wait for admin approval!"; ModelState.Clear(); emailHandler.SendMail(eModel, -1); } } catch (UserNotCreatedException ex) { Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, user.UserId, typeof(AuthController), ex); message = ex.Message; TempData["errorMsg"] = "Unable to register user Please try again later!"; //ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message)); } catch (UserAlreadyExists ex) { Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, user.UserId, typeof(AuthController), ex); message = ex.Message; TempData["errorMsg"] = "User already exist please login!"; //ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message)); } catch (Exception ex) { Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex); ViewData["SuccessMessage"] = "Unable to send Mail"; } return(View()); }
public IActionResult JobseekerRegistration(JobSeekerViewModel user) { var message = "User registered successfully, please login to proceed."; try { if (ModelState.IsValid) { user.RoleId = 2;//For Student authHandler.RegisterUser(user); SendRegistrationMailToJobSeeker(user); TempData["successMsg"] = "User registered successfully, please login to proceed."; ModelState.Clear(); } } catch (UserNotCreatedException ex) { Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, user.UserId, typeof(AuthController), ex); message = ex.Message; TempData["errorMsg"] = "Unable to register user Please try again later!"; //ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message)); } catch (UserAlreadyExists ex) { Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, user.UserId, typeof(AuthController), ex); message = ex.Message; TempData["errorMsg"] = "User already exist please login!"; //ModelState.AddModelError("ErrorMessage", string.Format("{0}", ex.Message)); } catch (Exception ex) { Logger.Logger.WriteLog(Logger.Logtype.Error, ex.Message, 0, typeof(AuthController), ex); ViewData["SuccessMessage"] = "Unable to send Mail"; } return(View()); }
public IActionResult RegisterAccount(RegisterUserInput inputUser) { if (string.IsNullOrWhiteSpace(inputUser.Username) || string.IsNullOrWhiteSpace(inputUser.Password) || string.IsNullOrWhiteSpace(inputUser.Captcha)) { _logger.LogInformation("Username, password or captcha is empty."); return(BadRequest()); } if (inputUser.Username.Length > 50) { _logger.LogInformation("Username exceeds permitted length."); return(BadRequest()); } if (!_captcha.VerifyCaptcha(inputUser.Captcha, HttpContext.Connection.RemoteIpAddress, "register")) { _logger.LogInformation("Captcha failed verification"); return(BadRequest()); } if (Guid.TryParse(inputUser.Token, out _) && _memoryCache.TryGetValue("R1" + inputUser.Token, out User cachedUser)) { _memoryCache.Remove("R1" + inputUser.Token); cachedUser.Password = inputUser.Password; cachedUser.Username = inputUser.Username.ToLower(); if (_authHandler.RegisterUser(ref cachedUser)) { _activityLogger.LogRegister(Request.HttpContext.Connection.RemoteIpAddress, cachedUser); return(Ok()); } _logger.LogInformation("Auth handler rejected account."); return(BadRequest()); } _logger.LogInformation("Token is invalid."); return(BadRequest()); }