Ejemplo n.º 1
0
        public AuthModel Login([FromBody] AccountLoginModel model)
        {
            var user = _readOnlyRepository.FirstOrDefault <Account>(x => x.Email == model.Email);

            if (user == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "User doesn't exist.");
            }
            if (!user.CheckPassword(model.Password))
            {
                throw new HttpException((int)HttpStatusCode.Unauthorized, "Password doesn't match.");
            }

            var authModel = new AuthModel
            {
                email        = user.Email,
                access_token = AuthRequestFactory.BuildEncryptedRequest(user.Email),
                role         = new RoleModel
                {
                    bitMask = 2, title = "admin"
                }
            };

            return(authModel);
        }
Ejemplo n.º 2
0
        public AuthModel ForgotPassword([FromBody] ResetpPaswordModel model)
        {
            var user = _readOnlyRepository.FirstOrDefault <Account>(x => x.Email == model.Email);
            var resp = SendSimpleMessage(model.Email, user.Password);

            if (user == null)
            {
                throw new HttpException((int)HttpStatusCode.NotFound, "User doesn't exist.");
            }
            var authModel = new AuthModel
            {
                Email       = user.Email,
                AccessToken = AuthRequestFactory.BuildEncryptedRequest(user.Email),
                role        = new RoleModel
                {
                    bitMask = 2,
                    title   = "admin"
                }
            };

            return(authModel);
        }