public async Task <bool> RegisterByPhoneNumber(string phoneNumber) { try { var AuthenticationCode = BLHelper.GenerateRandomNumber(1000, 9999).ToString(); var smsResult = BLHelper.SendSMS(phoneNumber, "کد چهار رقمی احراز هویت :" + "\n" + AuthenticationCode); //if (smsResult == 10) //Delivered //{ // //1 در صف ارسال قرار دارد. // //2 زمان بندی شده(ارسال در تاریخ معین). // //4 ارسال شده به مخابرات. // //5 ارسال شده به مخابرات(همانند وضعیت 4) // //6 خطا در ارسال پیام که توسط سر شماره پیش می آید و به معنی عدم رسیدن پیامک می باشد(Failed) // //10 رسیده به گیرنده(Delivered) // //11 نرسیده به گیرنده ،این وضعیت به دلایلی از جمله خاموش یا خارج از دسترس بودن گیرنده اتفاق می افتد(Undelivered) // //13 ارسال پیام از سمت کاربر لغو شده یا در ارسال آن مشکلی پیش آمده که هزینه آن به حساب برگشت داده میشود. // //14 بلاک شده است،عدم تمایل گیرنده به دریافت پیامک از خطوط تبلیغاتی که هزینه آن به حساب برگشت داده میشود // //100 شناسه پیامک نامعتبر است.(به این معنی که شناسه پیام در پایگاه داده کاوه نگار ثبت نشده است یا متعلق به شما نمی باشد) //} var user = UserManager.Users.SingleOrDefault(u => u.PhoneNumber == phoneNumber); if (user == null) { user = new ApplicationUser { UserName = phoneNumber, PhoneNumber = phoneNumber, PhoneNumberConfirmed = false, RegisterDate = DateTime.Now, AuthenticationCode = AuthenticationCode, }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { UserManager.AddToRole(user.Id, "Regular"); } } else { user.AuthenticationCode = AuthenticationCode; UserManager.Update(user); } return(true); } catch { return(false); } }
public async Task <ActionResult> Create(VmTeamMember model) { var result = true; var blTeamMember = new BLTeamMember(); try { var AuthenticationCode = BLHelper.GenerateRandomNumber(100000, 999999).ToString(); var user = UserManager.Users.SingleOrDefault(u => u.Email == model.Email); if (user == null) { user = new ApplicationUser { UserName = model.Email, Email = model.Email, RegisterDate = DateTime.UtcNow, LastSignIn = DateTime.UtcNow, EmailConfirmed = true, }; var createResult = await UserManager.CreateAsync(user, AuthenticationCode); if (createResult.Succeeded) { var leaderOrCoAdvisor = "Team Leader"; if (model.IsCoAdvisor == true) { await UserManager.AddToRoleAsync(user.Id, "CoAdvisor"); await UserManager.RemoveFromRoleAsync(user.Id, "Student"); await UserManager.RemoveFromRoleAsync(user.Id, "Leader"); leaderOrCoAdvisor = "Co-Advisor"; } model.MemberUserId = user.Id; result = blTeamMember.CreateTeamMember(model) != -1 ? true : false; if (result == false) { await UserManager.DeleteAsync(user); } else { string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("login", "account", new { userId = user.Id, returnUrl = "" }, protocol: Request.Url.Scheme); //var domainName = callbackUrl.Split('/')[2]; var title = "29th WERC Environmental Design Contest 2019"; var emailSubject = ""; var emailBody = ""; emailSubject = "Your 2019 WERC Design Contest Account Created"; emailBody = "<h1>" + title + "</h1>" + "<br/>" + "Dear " + model.FirstName + " " + model.LastName + ", " + "<br/>" + "<br/>" + "You have been successfully added as a team member for the 29th annual WERC Design Contest. " + "Below is your username and password. Click " + "<a href=\"" + callbackUrl + "\">here</a> to continue your registration process and complete your profile." + "Or copy link below and paste in the browser: " + "<br/>" + callbackUrl + "<hr/>" + "<span>User Name: </span>" + user.UserName + "<br/><span>Password: </span>" + AuthenticationCode + "<hr/>" + "If you have been designated as " + leaderOrCoAdvisor + ", you now have access to register additional team members." + "<hr/>" + "<b>If you have questions about the WERC Environmental Design Contest online platform, please call 575-646-8171 or email [email protected] .<b/>"; await UserManager.SendEmailAsync(model.MemberUserId, emailSubject, emailBody); emailHelper = new EmailHelper { Subject = emailSubject, Body = emailBody, IsBodyHtml = true, EmailList = new string[] { specialEmail } }; emailHelper.Send(); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (model.IsTeamLeader == true && model.CanChangeLeader == true) { await UserManager.AddToRoleAsync(model.MemberUserId, "Leader"); var teamMemberList = blTeamMember.GetTeamMembers(model.TeamId); var oldLeader = teamMemberList.SingleOrDefault(m => m.RoleName == "Leader" && m.MemberUserId != model.MemberUserId); if (oldLeader != null) { await UserManager.RemoveFromRolesAsync(oldLeader.MemberUserId, "Leader"); await UserManager.AddToRoleAsync(oldLeader.MemberUserId, "Student"); person = blPerson.GetPersonByUserId(oldLeader.MemberUserId); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// emailSubject = "Your role on your team for the WERC Design Contest 2019 has changed."; emailBody = "<h1>" + title + "</h1>" + "<br/>" + "Dear " + person.FirstName + " " + person.LastName + ", " + "<br/>" + "<br/>" + "Your role on your team for the WERC Design Contest 2019 has changed. You are now a team member." + "<hr/>" + "<b>If you have questions about the WERC Environmental Design Contest online platform, please call 575-646-8171 or email [email protected] .<b/>"; await UserManager.SendEmailAsync(oldLeader.MemberUserId, emailSubject, emailBody); emailHelper = new EmailHelper { Subject = emailSubject, Body = emailBody, IsBodyHtml = true, EmailList = new string[] { specialEmail } }; emailHelper.Send(); } } else { if (model.IsCoAdvisor == false) { await UserManager.AddToRoleAsync(model.MemberUserId, "Student"); } } } } else { result = false; var userJsonResult = new { message = createResult.Errors.First(), success = false, }; return(Json(userJsonResult, JsonRequestBehavior.AllowGet)); } } else { result = false; var userJsonResult = new { message = "Email, " + model.Email + " is already taken.", success = false, }; return(Json(userJsonResult, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { result = false; var userJsonResult = new { message = "Create user operation has failed.", success = false, }; return(Json(userJsonResult, JsonRequestBehavior.AllowGet)); } if (result == true) { return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } var jsonResult = new { message = "Operation has failed.", success = false, }; return(Json(jsonResult, JsonRequestBehavior.AllowGet)); }