Ejemplo n.º 1
0
        public string Post([FromBody] RegisterParams register)
        {
            string username = register.Username;
            string password = register.Password;
            string email    = register.Email;

            using (UserProfileServiceReference.UserProfileManagementServiceClient client = new UserProfileServiceReference.UserProfileManagementServiceClient())
            {
                string status_msg     = null;
                bool   username_taken = client.IsUsernameTaken(username);
                bool   email_exists   = client.UserWithEmailIdExists(email);
                if (username_taken)
                {
                    status_msg = "This username is unavailable :/. ";
                    throw new HttpResponseException(SetHttpErrorMsg(status_msg, HttpStatusCode.BadRequest));
                }
                if (email_exists)
                {
                    status_msg = "An account with this email already exists -.- ";
                    throw new HttpResponseException(SetHttpErrorMsg(status_msg, HttpStatusCode.BadRequest));
                }
                UserProfileServiceReference.User user = new UserProfileServiceReference.User();
                user.Username = username;
                user.Password = password;
                user.EmailID  = email;
                client.RegisterUser(user);
                status_msg = "Registration Successful!";
                return(status_msg);
            }
        }
Ejemplo n.º 2
0
        public string Post([FromBody] ForgotParams forgot)
        {
            string emailID = forgot.Email;

            try
            {
                using (UserProfileServiceReference.UserProfileManagementServiceClient client = new UserProfileServiceReference.UserProfileManagementServiceClient())
                {
                    client.SendPasswordResetToken(emailID);
                }
            }
            catch (FaultException ex)
            {
                throw new HttpResponseException(SetHttpErrorMsg(ex.Reason.ToString(), HttpStatusCode.BadRequest));
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(SetHttpErrorMsg("Some unexpected error occurred :/", HttpStatusCode.InternalServerError));
                //throw new HttpResponseException(SetHttpErrorMsg(ex.Message, HttpStatusCode.InternalServerError));
            }
            return("Token sent on email");
        }
Ejemplo n.º 3
0
        public string Post([FromBody] ResetParams reset)
        {
            string npwd     = reset.NewPassword;
            string token    = reset.Token;
            string email_id = reset.Email;

            try
            {
                using (UserProfileServiceReference.UserProfileManagementServiceClient client = new UserProfileServiceReference.UserProfileManagementServiceClient())
                {
                    client.ResetPassword(token, email_id, npwd);
                    return("Password Reset Successfully!");
                }
            }
            catch (FaultException ex)
            {
                throw new HttpResponseException(SetHttpErrorMsg(ex.Reason.ToString(), HttpStatusCode.BadRequest));
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(SetHttpErrorMsg("Some unexpected error occurred :/" + ex.Message, HttpStatusCode.InternalServerError));
            }
        }