Пример #1
0
        public HttpResponseMessage Create(Bizdoc.Data.ViewModels.CreateUserModel model)
        {
            //Check that email is not in use
            if (repo.GetByEmail(model.Email)!=null)
            {
                ModelState.AddModelError("Email", "Email address already in use");
            }

            //Check password length
            if (model.Password.Length<6)
            {
                ModelState.AddModelError("Password", "Password must be at least 6 characters");
            }

            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            User user = UserManager.createUser(model.Email, model.Password);

            UserTicket ticket = new UserTicket(user);
            new UserTicketRepository().Create(ticket);

            var response = Request.CreateResponse<UserTicket>(HttpStatusCode.Created, ticket);
            return response;
        }
Пример #2
0
        public static void setCookie(ControllerContext context, UserTicket ticket)
        {
            HttpCookie cookie = new HttpCookie("BizDoc-Login");
            cookie.Value = ticket.id.ToString();
            cookie.Domain = "bizdoc.dk";
            cookie.Expires = DateTime.Now.AddDays(30);

            context.HttpContext.Response.Cookies.Add(cookie);
        }
Пример #3
0
        public HttpResponseMessage Login(Bizdoc.Data.ViewModels.LoginModel model)
        {
            int errorCode = 0;
            User u = repo.GetByEmail(model.Email);

            if (u==null)
            {
                errorCode = 2;
                //ModelState.AddModelError("Email", "Wrong email");
            }
            else
            {
                if (!u.passwordMatches(model.Password))
                {
                    errorCode = 1;
                    //ModelState.AddModelError("Password", "Wrong password");
                }
                //else
                //{
                //    if (u.emails.Where(o => o.email == model.Email).First().denied)
                //    {
                //        ModelState.AddModelError("Email", "The email address has been denied use by the owner");
                //    }
                //    else
                //    {
                //        if (!u.emails.Where(o => o.email == model.Email).First().verified)
                //        {
                //            ModelState.AddModelError("Email", "The email address has not been verified by the user");
                //        }
                //    }
                //}
            }

            if (errorCode!=0)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, errorCode.ToString());
            }

            UserTicket ticket = new UserTicket(u);
            new UserTicketRepository().Create(ticket);

            var response = Request.CreateResponse<UserTicket>(HttpStatusCode.Created, ticket);
            return response;
        }