예제 #1
0
 public ActionResult New(RegistrUserVM user, HttpPostedFileBase fileUpload)
 {
     if (ModelState.IsValid)
     {
         if (fileUpload != null)
         {
             var            res             = ImageHelper.ScaleImage(Image.FromStream(fileUpload.InputStream, true, true), 200, 200);
             ImageConverter _imageConverter = new ImageConverter();
             byte[]         xByte           = (byte[])_imageConverter.ConvertTo(res, typeof(byte[]));
             user.Photo = xByte;
         }
         UserData newUser = new UserData();
         try
         {
             newUser = dataHelper.CreateUser(user, passwordHelper.CryptPassword(user.Password));
         }
         catch (ValidationException ve)
         {
             ModelState.AddModelError(ve.Property, ve.Message);
             return(View(user));
         }
         emailHelper.SendRegistrationMessage(newUser.Login, newUser.PasswordHash, newUser.Email, EmailHelper.EmailType.Registration);
         logger.InfoMessage("101", $"Send conf email to {newUser.Login} : {newUser.Email}");
         return(View("RegistrationLink", newUser));        //for test
     }
     else
     {
         return(View(user));
     }
 }
예제 #2
0
        public string AddUser(AddUserRequest a)
        {
            var       newEncpassword = BCrypt.Net.BCrypt.HashPassword(a.Password, 13);
            WritaUser newUser        = new WritaUser()
            {
                EmailAddress          = a.EmailAddress,
                DateRegistered        = DateTime.Now,
                DateLastLogin         = DateTime.Now,
                UserFullName          = a.UserFullName,
                UserPasswordEncrypted = newEncpassword,
                UserIpAddress         = ""
            };

            WritaUser u = _dbhelper.CreateUser(newUser);

            return("User " + a.EmailAddress + " was created");
        }
예제 #3
0
        public ActionResult Register(string password, string username, string email, string subscribetonews)
        {
            var newEncpassword = BCrypt.Net.BCrypt.HashPassword(password, 13);

            bool subscribe = false;

            if (subscribetonews == "on")
            {
                subscribe = true;
                // this subscribes the new user to the write newsletter by pinging the writa.org API.
                try
                {
                    var client  = new RestClient("http://writa.org");
                    var request = new RestRequest("api/notify/subscribe", Method.GET);
                    request.AddParameter("email", email);
                    request.AddParameter("name", username);
                    IRestResponse response = client.Execute(request);
                    var           content  = response.Content; // raw content as string
                }
                catch { }
            }

            var ux = _dbhelper.GetUserByEmail(new WritaUser()
            {
                EmailAddress = email
            });

            if (ux == null)
            {
                WritaUser newUser = new WritaUser()
                {
                    EmailAddress          = email,
                    DateRegistered        = DateTime.Now,
                    DateLastLogin         = DateTime.Now,
                    UserFullName          = username,
                    UserPasswordEncrypted = newEncpassword,
                    UserIpAddress         = Request.ServerVariables["REMOTE_ADDR"]
                };

                WritaUser u = _dbhelper.CreateUser(newUser);

                foreach (WritaPost w in _dbhelper.GetAllPosts())
                {
                    w.PostAuthorID           = u.Id;
                    w.PostLastEditedAuthorID = u.Id;
                    w.PostLastEditedAuthor   = u.UserFullName;
                    w.PostAuthor             = u.UserFullName;
                    _dbhelper.UpdatePost(w);
                }

                //send registration email?
                //var fullurl = this.Url.Action("ValidateAccount", "Account", null, this.Request.Url.Scheme);

                //var template = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/UserActivationTemplate.txt"));
                //template = template.Replace("{activationurl}", fullurl + "?key=" + u.Id + "&eml=" + u.EmailAddress);
                //NotificationEmailhelper.SendUserActivationEmail(u.Id, u.EmailAddress, template);
                //

                FormsAuthentication.RedirectFromLoginPage(u.Id, false);
            }
            else
            {
                ViewBag.RegisterError = "An account already exists";
            }


            return(View("Index"));
        }