Example #1
0
        public static void Register(HttpRequestBase req, HttpResponseBase res)
        {
            string login    = req["login"];
            string password = req["password"];

            if (!_commonLogic.CheckLogin(login))
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Login occupied")));
                return;
            }

            var registeredAdmin = _adminLogic.Register(new Admin
            {
                Login       = login,
                Password    = Convert.ToBase64String(_sha256.ComputeHash(Encoding.Unicode.GetBytes(password))),
                IsCandidate = true,
                Role        = "ADMIN"
            });

            if (registeredAdmin.Id == 0)
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Database error")));
                return;
            }


            res.Write(JsonConvert.SerializeObject(new RequestResult("Success",
                                                                    "You have been registered as Administrator. Wait for verification by administrators.")));
            return;
        }
        public static void Register(HttpRequestBase req, HttpResponseBase res)
        {
            string firstName  = req["firstName"];
            string lastName   = req["lastName"];
            string city       = req["city"];
            bool   relocation = req["relocation"] == "true";
            string login      = req["login"];
            string password   = req["password"];
            var    image      = req.Files["image"];

            if (!_commonLogic.CheckLogin(login))
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Login occupied.")));
                return;
            }

            var employee = new Employee
            {
                FirstName  = firstName,
                LastName   = lastName,
                City       = city,
                Relocation = relocation,
                Login      = login,
                Password   = Convert.ToBase64String(_sha256.ComputeHash(Encoding.Unicode.GetBytes(password))),
                Photo      = string.Empty
            };

            if (image != null && image.ContentLength != 0)
            {
                var bytes = new byte[image.ContentLength];
                image.InputStream.Read(bytes, 0, bytes.Length);
                employee.Photo = Convert.ToBase64String(bytes);
            }

            employee = _employeeLogic.Register(employee);
            if (employee.Id == 0)
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Error", "Something went wrong.")));
                return;
            }
            else
            {
                res.Write(JsonConvert.SerializeObject(new RequestResult("Success", "Successfully registered.")));
                return;
            }
        }