public ActionResult Reject(UserModel model)
        {
            model.Approved = false;

            model.Rejected = true;

            this.ServiceResponse = userService.ChangeUserStatus(this.CurrentUser, model);

            if (this.ServiceResponse.IsOK)
            {
                var emailModel = new UserServices().GetUserEmailModel(this.CurrentUser, model).Model as SendEmailModel;

                emailModel.Subject           = "New Project Office Registration Rejection";
                emailModel.RenderTextVersion = true;

                emailModel.BodyTextVersion = RenderView(this, "SendEmailUserRejection", emailModel);

                emailModel.RenderTextVersion = false;
                emailModel.BodyHtmlVersion   = RenderView(this, "SendEmailUserRejection", emailModel);

                var emailservice = new EmailServices();
                emailservice.SendEmail(emailModel);

                this.ServiceResponse.AddSuccess("Email sent to user");
            }

            ProcessServiceResponse(this.ServiceResponse);

            this.ServiceResponse.Messages.Clear();

            return(AjaxReloadPage());
        }
Example #2
0
        public async Task <string> Create(NewAccountInfo newAccountInfo)
        {
            await DatabaseFunctions.InitializeStaticStorage(_db).ConfigureAwait(false);

            if (newAccountInfo is null)
            {
                return("No credentials received");
            }

            newAccountInfo.CredentialsUsername = newAccountInfo.CredentialsUsername.ToLower();
            // checks if the email is legit or not
            if (!EmailServices.VerifyEmail(newAccountInfo.CredentialsUsername))
            {
                return("Invalid email");
            }

            var credentialList = await DatabaseFunctions.GetCredentials(_db, newAccountInfo).ConfigureAwait(false);

            if (credentialList.Count != 0)
            {
                return("Email already exists");
            }

            var pcCredentialPassword = await DatabaseFunctions.CreateNewCredentials(_db, newAccountInfo).ConfigureAwait(false);

            await DatabaseFunctions.CreateNewAdmin(_db, newAccountInfo).ConfigureAwait(false);

            StaticStorageServices.PcMapper.Add(newAccountInfo.CredentialsUsername, new Dictionary <string, DiagnosticData>());

            //send pcCredential password to the new user
            await EmailServices.SendEmail(newAccountInfo.CredentialsUsername, $"Pc Credential Password: {pcCredentialPassword}");

            return("Success");
        }
Example #3
0
        [HttpPost]                                          // query string
        public async Task <bool> ForgetPasswordUsername(string credentialUsername)
        {
            await DatabaseFunctions.InitializeStaticStorage(_db).ConfigureAwait(false);

            try
            {
                credentialUsername = credentialUsername.ToLower();
                var credentialFromDb = await _db.Credentials.Where(c => c.CredentialsUsername.Equals(credentialUsername))
                                       .FirstOrDefaultAsync().ConfigureAwait(false);

                if (credentialFromDb == null)
                {
                    return(false);
                }

                var credentialUniqueId = ModelCreation.GenerateRandomString();

                // generate credentialUniqueId
                credentialFromDb.CredentialChangePasswordId = credentialUniqueId;
                await _db.SaveChangesAsync();

                // send it by email
                await EmailServices.SendEmail(credentialUsername, $"Verification Code: {credentialUniqueId}");

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
Example #4
0
        public ActionResult Register(RegisterModel registerModel)
        {
            if (ModelState.IsValid)
            {
                // Попытка зарегистрировать пользователя
                try
                {
                    Membership.CreateUser(registerModel.UserName, registerModel.Password);

                    ProfileBase profile = ProfileBase.Create(registerModel.UserName);
                    profile.SetPropertyValue("Name", registerModel.Name);
                    profile.SetPropertyValue("Surname", registerModel.Surname);
                    profile.SetPropertyValue("Patronymic", registerModel.Patronymic);
                    profile.SetPropertyValue("Email", registerModel.Email);
                    profile.SetPropertyValue("UserName", registerModel.UserName);
                    profile.Save();

                    Roles.AddUserToRole(registerModel.UserName, "Member");

                    EmailServices.SendEmail(registerModel);

                    return(RedirectToAction("RegisterContinue", "Account", new { username = registerModel.UserName }));
                }

                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // Появление этого сообщения означает наличие ошибки; повторное отображение формы
            return(View(registerModel));
        }
        public ActionResult Approve(UserModel model)
        {
            model.Approved = true;
            model.Rejected = false;

            this.ServiceResponse = userService.ChangeUserStatus(this.CurrentUser, model);

            if (this.ServiceResponse.IsOK)
            {
                var emailModel = new UserServices().GetUserEmailModel(this.CurrentUser, model).Model as SendEmailModel;

                emailModel.Subject           = "New Project Office Registration Approval";
                emailModel.RenderTextVersion = true;

                emailModel.BodyTextVersion = RenderView(this, "SendEmailUserApproval", emailModel);

                emailModel.RenderTextVersion = false;
                emailModel.BodyHtmlVersion   = RenderView(this, "SendEmailUserApproval", emailModel);

                var emailservice = new EmailServices();
                emailservice.SendEmail(emailModel);

                this.ServiceResponse.AddSuccess("Email sent to user");
            }

            ProcessServiceResponse(this.ServiceResponse);

            this.ServiceResponse.Messages.Clear();

            return(AJAXRedirectTo("ApprovalRequests", "UserDashboard", null));
        }
Example #6
0
        public ActionResult ForgotPassword(FormCollection form)
        {
            string email = form["email"].ToString();
            var    usr   = _usrService.GetUserProfile(email);

            if (ModelState.IsValid)
            {
                if (usr == null)
                {
                    // Don't reveal that the user does not exist or is not confirmed
                    return(View("Login"));
                }
                string passwordKey = KeyGenerator.GetUniqueKey(8);
                usr.PassWord = passwordKey;
                _usrService.SaveUserProfil(usr);
                string message = _emailService.ForgotPasswordContent(usr.PassWord);
                _emailService.SendEmail(usr.Email, "Password Recovery", message);

                return(RedirectToAction("ForgotPassword", "Account"));
            }


            // If we got this far, something failed, redisplay form
            return(View("Login"));
        }
Example #7
0
        public ActionResult EmailMessage(FormCollection form)
        {
            var from    = form["from"];
            var to      = form["to"];
            var search  = form["search"];
            var message = form["message"];
            var videoId = form["videoid"];

            var emailService = new EmailServices
            {
                From = new Mandrill.EmailAddress {
                    name = @from, email = @from
                },
                To = new List <Mandrill.EmailAddress> {
                    new Mandrill.EmailAddress {
                        email = to, name = ""
                    }
                },
                Subject = "Watch this play!",
                Message = string.Format("{0} : https://www.youtube.com/watch?v={1}", message, videoId)
            };

            emailService.SendEmail();

            var youtubeService = new YouTubeServices();
            var model          = youtubeService.GetMatchingVideos(search);

            return(View("Index", model));
        }
Example #8
0
        public ActionResult UserRegistration(UserModel model)
        {
            model.IsRegistering = true;

            // Lookup account by business name, state, postal code
            BusinessModel identifiedBusiness = SearchForBusiness(model);

            // In order to prevent duplicates we will lookup the business by name, state, postal code
            // and if it exists return back the business and send an email to the super user that a user
            // wants to register
            if (identifiedBusiness != null)
            {
                model.Business         = identifiedBusiness;
                model.ExistingBusiness = ExistingBusinessEnum.Existing;
            }

            this.ServiceResponse = userService.PostModel(this.CurrentUser, model);

            model = this.ServiceResponse.Model as UserModel;

            //this.ServiceResponse = userService.GetUserModel(this.CurrentUser, model);
            //model = this.ServiceResponse.Model as UserModel;

            if (ProcessServiceResponse(this.ServiceResponse))
            {
                if (model.IsRegistering)
                {
                    businessService.SetupDefaultPermission(this.CurrentUser, model.Business);
                    userService.SetupDefaultPermissions(this.CurrentUser, model);

                    try
                    {
                        var emailModel = userService.GetUserRegistrationEmailModel(model).Model as SendEmailModel;

                        emailModel.Subject           = "New Project Office Registration";
                        emailModel.RenderTextVersion = true;

                        emailModel.BodyTextVersion = RenderView(this, "SendEmailUserRegistration", emailModel);

                        emailModel.RenderTextVersion = false;
                        emailModel.BodyHtmlVersion   = RenderView(this, "SendEmailUserRegistration", emailModel);

                        var emailservice = new EmailServices();
                        emailservice.SendEmail(emailModel);
                    }
                    catch (Exception e)
                    {
                        Utilities.ErrorLog(e);
                    }
                }
                return(PartialView("RegistrationAcknowledgement", "Account"));
            }

            var userModel = this.ServiceResponse.Model as UserModel;

            return(PartialView("UserRegistration", this.ServiceResponse.Model));
        }
 public void Register(string email, string password)
 {
     if (!_emailService.ValidateEmail(email))
     {
         throw new Exception("Invalid email address.");
     }
     //other logic
     _emailService.SendEmail(new MailMessage("*****@*****.**", email)
     {
         Subject = "Test from SOLID"
     });
 }
Example #10
0
        public async Task <string> PostPcHealthDataFromPc(PcHealthData pcHealthData)
        {
            await DatabaseFunctions.InitializeStaticStorage(_db).ConfigureAwait(false);

            foreach (var admin in pcHealthData.PcConfiguration.Admins)
            {
                if (admin.Item2.Equals(StaticStorageServices.AdminMapper[admin.Item1]))
                {
                    await EmailServices.SendEmail(admin.Item1, $"In the last minute, the pc of name {pcHealthData.PcConfiguration.PcUsername} " +
                                                  $"hit over 80%: <br>Memory Usage: {pcHealthData.MemoryHighCounter} times <br>" +
                                                  $"Cpu Usage: {pcHealthData.CpuHighCounter} times.");
                }
            }
            return("true");
        }
        //
        // GET: /Email/
        public JsonResult SendEmail(EmailEntity emailEntity)
        {
            Message msg = new Message();

            try
            {
                EmailServices.SendEmail(emailEntity);
                msg.MessageStatus = "true";
                msg.MessageInfo   = "上传成功";
            }
            catch (Exception ex)
            {
                msg.MessageStatus = "false";
                msg.MessageInfo   = ex.Message;
            }

            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Example #12
0
        public async Task <bool> ResetPcCredentialPassword(Credential credential)
        {
            await DatabaseFunctions.InitializeStaticStorage(_db).ConfigureAwait(false);

            try
            {
                credential.CredentialsUsername = credential.CredentialsUsername.ToLower();
                var credentialFromDb = await _db.Credentials
                                       .Where(c => c.CredentialsUsername.Equals(credential.CredentialsUsername)).FirstOrDefaultAsync()
                                       .ConfigureAwait(false);

                if (credentialFromDb == null)
                {
                    return(false);
                }

                var passwordSalt = await DatabaseFunctions.GetPasswordSalt(_db, credential).ConfigureAwait(false);

                var passwordInDatabase = await DatabaseFunctions.GetPasswordFromDb(_db, credential).ConfigureAwait(false);

                var decryptPassword = HashServices.Decrypt(passwordSalt, credential.CredentialsPassword);

                if (!decryptPassword.Equals(passwordInDatabase))
                {
                    return(false);
                }

                credentialFromDb.PcCredentialPassword = ModelCreation.GenerateRandomString();

                StaticStorageServices.AdminMapper[credential.CredentialsUsername] = credentialFromDb.PcCredentialPassword;

                await EmailServices.SendEmail(credential.CredentialsUsername, $"New Pc Credential Password: {credentialFromDb.PcCredentialPassword}");

                await _db.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
        public ActionResult Edit(ProductQuestion productQuestion, string sendEmail)
        {
            try
            {
                productQuestion.LastUpdate = DateTime.Now;

                ViewBag.Success = true;

                if (productQuestion.ID == -1)
                {
                    productQuestion.UserID   = UserID;
                    productQuestion.DateTime = DateTime.Now;

                    ProductQuestions.Insert(productQuestion);

                    UserNotifications.Send(UserID, String.Format("جدید - سوالات متداول '{0}'", productQuestion.Question), "/Admin/ProductQuestions/Edit/" + productQuestion.ID, NotificationType.Success);

                    productQuestion = new ProductQuestion();
                }
                else
                {
                    ProductQuestions.Update(productQuestion);

                    if (!String.IsNullOrWhiteSpace(productQuestion.UserID) && sendEmail == "on" && productQuestion.QuestionStatus == QuestionStatus.Answered)
                    {
                        var user = OSUsers.GetByID(productQuestion.UserID);

                        EmailServices.SendEmail(user.Email, "پاسخ به پرسش شما", productQuestion.Reply, user.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(ClearView(model: productQuestion));
        }
        public JsonResult ResetPassword(int id)
        {
            Message msg = new Message();

            SysUser sysuser         = unitOfWork.sysUsersRepository.GetByID(id);
            string  password        = CommonTools.GenerateRandomNumber(8);
            string  confirmpassword = CommonTools.ToMd5(password);
            string  sysemail        = sysuser.SysEmail;

            sysuser.SysPassword = confirmpassword;



            if (ModelState.IsValid)
            {
                unitOfWork.sysUsersRepository.Update(sysuser);
                unitOfWork.Save();
                string      EmailContent = "密码已经被重置为" + password.ToString() + ",并已经发送邮件到" + sysuser.SysEmail + ",请注意查收!";
                EmailServer server       = new EmailServer();
                Setting     setting      = unitOfWork.settingsRepository.GetByID(1);
                server.EmailAddress  = setting.EmailFrom;
                server.EmailPassword = setting.EmailPassword;
                server.SMTPClient    = setting.EmailHost;
                EmailEntity mailEntity = new EmailEntity();
                mailEntity.DisplayName = "星星家庭训练系统管理员";
                mailEntity.MailContent = EmailContent;
                mailEntity.ToMail      = sysemail;
                mailEntity.MailTitle   = "重置密码邮件";
                mailEntity.FromMail    = server.EmailAddress;
                EmailServices.SendEmail(server, mailEntity);

                //  AdsEmailServices.SendEmail(EmailContent,sysuser.SysEmail);

                msg.MessageStatus = "true";
                msg.MessageInfo   = EmailContent;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Example #15
0
        public ServiceResponse UserRegistration(UserModel model)
        {
            ServiceResponse response = new ServiceResponse();

            model.IsRegistering = true;
            // Lookup account by business name, state, postal code
            BusinessModel identifiedBusiness = SearchForBusiness(model);

            // In order to prevent duplicates we will lookup the business by name, state, postal code
            // and if it exists return back the business and send an email to the super user that a user
            // wants to register
            if (identifiedBusiness != null)
            {
                model.Business         = identifiedBusiness;
                model.ExistingBusiness = ExistingBusinessEnum.Existing;
            }

            response = userService.PostModel(this.CurrentUser, model);

            model = response.Model as UserModel;

            if (response.IsOK)
            {
                if (model.IsRegistering)
                {
                    businessService.SetupDefaultPermission(this.CurrentUser, model.Business);
                    userService.SetupDefaultPermissions(this.CurrentUser, model);

                    try
                    {
                        var emailModel = userService.GetUserRegistrationEmailModel(model).Model as SendEmailModel;

                        emailModel.Subject           = "New Project Office Registration";
                        emailModel.RenderTextVersion = true;

                        //emailModel.BodyTextVersion = RenderView(this, "SendEmailUserRegistration", emailModel);

                        //emailModel.BodyTextVersion = MvcAccountController.RenderView(MvcAccountController, "SendEmailUserRegistration", emailModel);

                        //GET
                        var serializedModel = JsonConvert.SerializeObject(emailModel);
                        var client          = new HttpClient();
                        var baseUrl         = Request.RequestUri.GetLeftPart(UriPartial.Authority);
                        var result          = client.GetAsync(baseUrl + "/ViewRender/Render?ViewName=UserRegistrationEmailTemplate&SerializedModel=" + serializedModel).Result;
                        //var result = client.GetAsync(baseUrl + "/Account/Render?ViewName=SendEmailUserRegistration&SerializedModel=" + serializedModel).Result;


                        //POST
                        //ViewRenderModel viewRenderModel = new ViewRenderModel
                        //{
                        //    ViewName = "SendEmailUserRegistration",
                        //    ViewModel = emailModel
                        //};
                        //var result = client.PostAsJsonAsync(baseUrl + "/ViewRender/Render", viewRenderModel).Result;

                        emailModel.RenderTextVersion = false;
                        //emailModel.BodyHtmlVersion = RenderView(this, "SendEmailUserRegistration", emailModel);
                        var emailservice = new EmailServices();
                        emailservice.SendEmail(emailModel);
                    }
                    catch (Exception e)
                    {
                        Utilities.ErrorLog(e);
                    }
                }
                //return PartialView("RegistrationAcknowledgement", "Account");
            }

            //var userModel = response.Model as UserModel;

            //return PartialView("UserRegistration", this.ServiceResponse.Model);
            return(response);
        }