public async Task <IActionResult> ExternalLoginConfirmation(ExternalLoginViewModel model, string returnUrl = null) { ViewData["Page"] = "external-login-confirmation"; 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(SiteConfig.generalLocalizer["_error_external_login_information"].Value); } var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, created_at = DateTime.Now, isenabled = 1 }; var result = await SiteConfig.userManager.CreateAsync(user); if (result.Succeeded) { // Init User Profile await UserProfileBLL.InitializeUserProfile(_context, user); // Create Required Directories Directory_Process.CreateRequiredDirectories(SiteConfig.Environment.ContentRootPath + UtilityBLL.ParseUsername(SystemDirectoryPaths.UserDirectory, user.Id.ToString())); result = await SiteConfig.userManager.AddLoginAsync(user, info); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } AddErrors(result); } ViewData["ReturnUrl"] = returnUrl; return(View("~/Views/Home/index.cshtml", model)); }
public async Task <IActionResult> register(RegisterViewModel model, string returnUrl = null) { ViewData["Page"] = "signup"; if (Configs.RegistrationSettings.uniqueFieldOption == 1) { ModelState.Remove("UserName"); } if (ModelState.IsValid) { // Rechapcha Validation if (Configs.RegistrationSettings.enableChapcha) { var recaptcha = await _recaptcha.Validate(Request); if (!recaptcha.success) { ModelState.AddModelError("Recaptcha", SiteConfig.generalLocalizer["_invalid_chapcha"].Value); return(View("~/Views/Home/index.cshtml", model)); } } if (Configs.RegistrationSettings.enablePrivacyCheck) { if (!model.Agreement) { ModelState.AddModelError(string.Empty, SiteConfig.generalLocalizer["_accept_aggrement"].Value); return(View("~/Views/Home/index.cshtml", model)); } } var UserName = model.UserName; if (Configs.RegistrationSettings.uniqueFieldOption == 1) { UserName = model.Email; } var user = new ApplicationUser { UserName = UserName, Email = model.Email, created_at = DateTime.Now, firstname = model.FirstName, lastname = model.LastName, isenabled = 1, type = (byte)UserBLL.Types.NormalUser }; var result = await SiteConfig.userManager.CreateAsync(user, model.Password); if (result.Succeeded) { // Init User Profile await UserProfileBLL.InitializeUserProfile(_context, user); // Create Required Directories Directory_Process.CreateRequiredDirectories(SiteConfig.Environment.ContentRootPath + UtilityBLL.ParseUsername(SystemDirectoryPaths.UserDirectory, user.Id.ToString())); var code = await SiteConfig.userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); await _emailSender.SendEmailConfirmationAsync(_context, model.Email, UserName, callbackUrl, model.Password); await _emailSender.SendEmailNotificationAsync(_context, model.Email, UserName); var redirect_url = "/activate"; if (returnUrl != null && returnUrl != "") { redirect_url = returnUrl; } return(Redirect(redirect_url)); } AddErrors(result); } return(View("~/Views/Home/index.cshtml", model)); }
public async Task <ActionResult> proc() { var json = new StreamReader(Request.Body).ReadToEnd(); var data = JsonConvert.DeserializeObject <ApplicationUser>(json); if (data.Id != null && data.Id != "") { // Update Profile var record = await UserBLL.Update_User_Profile(_context, data, data.isadmin); /* attribute processing */ foreach (var attr in data.attr_values) { attr.userid = data.Id; attr.attr_type = (byte)Attr_Type.UserProfile; if (attr.id > 0) { /* update record */ await AttrValueBLL.Update(_context, attr); } else { /* add attribute */ if (attr.value != "") { await AttrValueBLL.Add(_context, attr); } } } record.img_url = UserUrlConfig.ProfilePhoto(record.UserName, record.picturename, 0); return(Ok(new { status = "success", record = record, message = SiteConfig.generalLocalizer["_record_updated"].Value })); } else { // Create New Account var user = new ApplicationUser { UserName = data.UserName, Email = data.Email, created_at = DateTime.Now, isenabled = 1, // internal use only (to suspend user account and all posted data at once) firstname = data.firstname, lastname = data.lastname }; var result = await SiteConfig.userManager.CreateAsync(user, data.password); if (result.Succeeded) { // role process if (data.role_name != null && data.role_name != "") { var roleExist = await SiteConfig.roleManager.RoleExistsAsync(data.role_name); if (!roleExist) { ApplicationRole role = new ApplicationRole(); role.Name = data.role_name; role.CreatedDate = DateTime.Now; await SiteConfig.roleManager.CreateAsync(role); } await SiteConfig.userManager.AddToRoleAsync(user, data.role_name); } // Init User Profile await UserProfileBLL.InitializeUserProfile(_context, user); Directory_Process.CreateRequiredDirectories(SiteConfig.Environment.ContentRootPath + UtilityBLL.ParseUsername(SystemDirectoryPaths.UserDirectory, user.Id.ToString())); // enable account directly UserBLL.Update_Field_Id(_context, user.Id, "EmailConfirmed", true); // setup url / picture url for app use only data.Id = user.Id; data.picturename = "none"; data.LockoutEnabled = false; data.EmailConfirmed = true; data.img_url = UserUrlConfig.ProfilePhoto(data.UserName, data.picturename, 0); // default set data.url = UserUrlConfig.ProfileUrl(data, Configs.RegistrationSettings.uniqueFieldOption); return(Ok(new { status = "success", record = data, message = SiteConfig.generalLocalizer["_account_created"].Value })); } else { return(Ok(new { status = "error", record = data, message = SiteConfig.generalLocalizer["_account_failed"].Value })); } } }